Lesson 9: The Format Procedure

Overview Section

We previously learned how to use a FORMAT statement to tell SAS to display certain variable values in a particular way. For example, we might tell SAS to display a date variable saledate, say, using the SAS mmddyy10. format, so that August 19, 2008,f is displayed as 08/19/2008. There are a whole slew of informats and formats that SAS provides that you can find in the SAS Help and Documentation. Our focus in this lesson will be on creating informats and formats to fill in for those that SAS doesn't provide.

That is, in this lesson, we will extend our formatting capabilities by investigating how to create user-defined informats and formats using the FORMAT procedure. In particular, we will take a look at the following techniques:

  • how to translate values of a character variable when they are read in a SAS data set into more meaningful values using the INVALUE statement
  • how to create customized formats for character and numeric variables, using the VALUE statement, so variables can be printed in a meaningful format
  • how to create templates, using the PICTURE state,ment, for printing numbers with a special format, such as leading zeros, decimal and comma punctuation, fill characters, and prefixes.

Objectives

Upon completion of this lesson, you should be able to:

Upon completing this lesson, you should be able to do the following:

  • create an ASCII file from a SAS data set using a PUT statement
  • tell SAS how to read in special characters using an INVALUE statement in the FORMAT procedure
  • associate a character variable with a particular informat
  • create a permanent formats catalog for a SAS data set
  • tell SAS how to print certain variables using a VALUE statement in the FORMAT procedure
  • define categories using a format
  • access a data set with permanently formatted variables without having access to the formats catalog by running the the NOFMTERR option
  • include a secondary program file in a main SAS program using the %INCLUDE statement
  • define formats using a codebook to help 
  • create templates for printing numbers by defining a format that allows for special characters using a PICTURE format  
  • instruct SAS to print the contents of a formats catalog using the FMTLIB option of the FORMAT procedure