![]() Chapter Contents |
![]() Previous |
![]() Next |
| The FORMAT Procedure |
| Associating Informats and Formats with Variables |
Associating Informats and Formats with Variables summarizes the different methods for associating informats and formats with variables.
| Step | Informats | Formats | |
|---|---|---|---|
| In a DATA step | Use the ATTRIB or INFORMAT statement to permanently associate an informat with a variable. Use the INPUT function or INPUT statement to associate the informat with the variable only for the duration of the DATA step. | Use the ATTRIB or FORMAT statement to permanently associate a format with a variable. Use the PUT function or PUT statement to associate the format with the variable only for the duration of the DATA step. | |
| In a PROC step | The ATTRIB and INFORMAT statements are valid in base SAS procedures. However, in base SAS software, typically you do not assign informats in PROC steps because the data have already been read into SAS variables. | Use the ATTRIB statement or the FORMAT statement to associate formats with variables. If you use either statement in a procedure that produces an output data set, the format is permanently associated with the variable in the output data set. If you use either statement in a procedure that does not produce an output data set, the statement associates the format with the variable only for the duration of the PROC step. | |
| Storing Informats and Formats |
PROC FORMAT stores user-written informats and formats as entries in SAS catalogs.(footnote 1) You use the LIBRARY= option in the PROC FORMAT statement to indicate the catalog. The name of the catalog entry is the name of the format or informat. The entry types are
Informats and formats are temporary when you do not specify the LIBRARY=
option in the PROC FORMAT statement. If you omit the LIBRARY= option, PROC
FORMAT stores the informats and formats in the temporary catalog WORK.FORMATS.
You can retrieve temporary informats and formats only in the same SAS session
or job in which they are created. To retrieve a temporary format or informat,
simply include the name of the format or informat in the appropriate SAS statement.
The SAS System automatically looks for the format or informat in the WORK.FORMATS
catalog.
If you want to use a format or informat that is created in one SAS job or session in a subsequent job or session, you must permanently store the format or informat in a SAS catalog.
You can create permanent informats and formats by using the LIBRARY=
option in the PROC FORMAT statement. See the discussion of the LIBRARY= option
in PROC FORMAT Statement.
After you have permanently stored an informat or format, you can use it in later SAS sessions or jobs. If you associate permanent informats or formats with variables in a later SAS session or job, SAS must be able to access the informats and formats. Thus, you must use a LIBNAME statement to assign a libref to the library that stores the catalog that stores the informats or formats.
SAS always searches the WORK.FORMATS and the LIBRARY.FORMATS catalogs for any user-defined informats or formats that you associate with variables. If you want to specify a search order for catalogs, or if you want to specify additional catalogs for SAS to search, use the SAS system option FMTSEARCH=. For further information on FMTSEARCH=, see the section on SAS system options in SAS Language Reference: Dictionary. For an example that uses the LIBRARY= and FMTSEARCH= options together, see Writing Ranges for Character Strings.
![[cautend]](../common/images/cautend.gif)
options nofmterr;
Refer to the section on SAS system options in SAS Language Reference: Dictionary for more information on NOFMTERR.
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.