FORMAT Procedure

Overview: FORMAT Procedure

What Does the FORMAT Procedure Do?

The FORMAT procedure enables you to define your own informats and formats for variables. In addition, you can print the parts of a catalog that contain informats or formats, store descriptions of informats or formats in a SAS data set, and use a SAS data set to create informats or formats.

What Are Formats and Informats?

Informats determine how raw data values are read and stored. Formats determine how variable values are printed. For simplicity, this section uses the terminology the informat converts and the format prints.
Informats and formats tell SAS the data's type (character or numeric) and form (such as how many bytes it occupies; decimal placement for numbers; how to handle leading, trailing, or embedded blanks and zeros; and so on). SAS provides informats and formats for reading and writing variables. For a thorough description of informats and formats that SAS provides, see SAS Formats and Informats: Reference.
With informats, you can do the following:
  • Convert a number to a character string (for example, convert 1 to YES).
  • Convert a character string to a different character string (for example, convert 'YES' to 'OUI').
  • Convert a character string to a number (for example, convert YES to 1).
  • Convert a number to another number (for example, convert 0–9 to 1, 10–100 to 2, and so on).
Note: User-defined informats read-only character data. They can convert character values into real numeric values, but they cannot convert real numbers into characters.
With formats, you can do the following:
  • Print numeric values as character values (for example, print 1 as MALE and 2 as FEMALE).
  • Print one character string as a different character string (for example, print YES as OUI).
  • Print numeric values using a template (for example, print 9458763450 as 945-876-3450).

How Are Formats and Informats Associated with a Variable?

The following figure summarizes what occurs when you associate an informat and format with a variable. The COMMAw.d informat and the DOLLARw.d format are provided by SAS.
Associating an Informat and a Format with a Variable
Associating an Informat and a Format with a Variable
In the figure, SAS reads the raw data value that contains the dollar sign and comma. The COMMA9.2 informat ignores the dollar sign and comma and converts the value to 1544.32. The DOLLAR9.2 format prints the value, adding the dollar sign and comma. For more information about associating informats and formats with variables, see Associating Informats and Formats with Variables .