FORMAT Procedure

Example 2: Creating a Picture Format

Features:

PROC FORMAT statement options: LIBRARY=

PICTURE statement options:
MULT=
PREFIX=

LIBRARY libref

LOW and HIGH keywords

Data set: PROCIB.STAFF

Details

This example uses a PICTURE statement to create a format that prints the values for the variable Salary in the data set PROCLIB.STAFF in U.S. dollars.

Program

libname proclib 'SAS-library-1 ';
libname library 'SAS-library-2';
options nodate pageno=1 linesize=80 pagesize=40;
   proc format library=library;
      picture uscurrency low-high='000,000' (mult=1.61 prefix='$');
   run;
proc print data=proclib.staff noobs label;
   label salary='Salary in U.S. Dollars';
   format salary uscurrency.;
   title 'PROCLIB.STAFF with a Format for the Variable Salary';
run;

Program Description

Assign two SAS library references (PROCLIB and LIBRARY). Assigning a library reference LIBRARY is useful in this case because if you use PROC FORMAT, then SAS automatically searches for informats and formats in any library that is referenced with the LIBRARY libref.
libname proclib 'SAS-library-1 ';
libname library 'SAS-library-2';
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=40;
Specify that user-defined formats will be stored in the catalog LIBRARY.FORMATS. The LIBRARY= option specifies a SAS catalog that will contain the formats or informats that you create with PROC FORMAT. When you create the library named LIBRARY, SAS automatically creates a catalog named FORMATS inside LIBRARY.
   proc format library=library;
Define the USCurrency. picture format. The PICTURE statement creates a template for printing numbers. LOW-HIGH ensures that all values are included in the range. The MULT= statement option specifies that each value is multiplied by 1.61. The PREFIX= statement adds a US dollar sign to any number that you format. The picture contains six digit selectors, five for the salary and one for the dollar sign prefix.
      picture uscurrency low-high='000,000' (mult=1.61 prefix='$');
   run;
Print the PROCLIB.STAFF data set. The NOOBS option suppresses the printing of observation numbers. The LABEL option uses variable labels instead of variable names for column headings.
proc print data=proclib.staff noobs label;
Specify a label and format for the Salary variable. The LABEL statement substitutes the specific label for the variable in the report. In this case, “Salary in US Dollars” is substituted for the variable Salary for this print job only. The FORMAT statement associates the USCurrency. format with the variable name Salary for the duration of this procedure step.
   label salary='Salary in U.S. Dollars';
   format salary uscurrency.;
Specify the title.
   title 'PROCLIB.STAFF with a Format for the Variable Salary';
run;

Output

PROCLIB.STAFF with a Format for the Variable Salary
PROCLIB.STAFF with a Format for the Variable Salary