Introduction to SAS format.

A SAS format is a set of instructions to the SAS system about how to WRITE or DISPLAY a stores value (or) Format is an instruction that SAS uses to write data values.

SAS Format syntax:-

  • Syntax: <$>format<w>.<d>
$$ indicates a character format, its absence indicates a numeric format.
WW is the maximum number of columns used to display the data values
DD is an optional number of decimal places for numeric values, the default number of decimal places is 0. All formats must contains a dot as part of the name.
ADVERTISEMENT

Format Statement

Format statement associates format variables, it writes the standard data to the output. We can use SAS format statement in both datastep (permanently) and PROC step (for print formats in output only).

SAS Variable attributesFunctionUsage in a DATA stepUsage in a PROC
InformatInput DataUse with the INPUT, ATTRIB or INFORMAT statement. Use with the INPUT, INPUTN or INPUT function.INFORMAT statements are rarely used in PROCs. Exception are PROCs that are used to input data such as PROC FSEDIT.
FormatOutput data (or) format data in reports.Use with the PUT, ATTRIB or FORMAT statement. Use with the PUT, PUTC or PUTN function.Use the ATTRIB or FORMAT statement.

Categories of Formats:-

  1. Character Formats :- Writes character data values from character variables. Character Informats and Character formats are same.
  2. Numeric Formats :- It writes numeric data values form numeric variables.
  3. Date, Time and Datetime Formats :- It writes date values from variables representing Time, Date and Date time variables.
  4. Column binary Formats :- Writes data stored in column-binary or multiple -punched form into character and numeric variables.
  5. User defined Formats :- These are created using PROC format.

SAS Format example program:-

For example, the number 2018 can be written in several ways as shown in below program.

Data formatexample;
 retain var1 - var5 2018;
run;
Proc print data=formatexample width=min noobs;
   format  var1 comma. var2 dollar9. var3 roman20. var4 mmddyy10. var5 mmddyyd10.;
run;

Output:-

SAS format Overview- example program