Creating SAS Data Sets from Custom Formats

Overview

You know how to create a format from a SAS data set, but what if you want to create a SAS data set from a format? To do this, you use the CNTLOUT= option.
General form, CNTLOUT= option in PROC FORMAT:
PROC FORMAT LIBRARY=libref.catalog CNTLOUT=SAS-data-set;
SELECT format-name format-name...;
EXCLUDE format-name format-name...;
RUN;
Here is an explanation of the syntax:
libref.catalog
is the name of the catalog in which the format is located.
SAS-data-set
is the name of the SAS data set that you want to create.
format-name
is the name of the format that you want to select or exclude.
The output control data set will contain variables that completely describe all aspects of each format, including optional settings. The output data set contains one observation per range per format in the specified catalog. You can use either the SELECT or EXCLUDE statement to include specific formats in the data set.
Creating a SAS data set from a format is very useful when you need to modify a format but no longer have the SAS data set you used to create the format. When you need to update a format, you take the following actions:
  1. Create a SAS data set from the values in a format using CNTLOUT=.
  2. Edit the data set using any number of methods.
  3. Create a format from the updated SAS data set using CNTLIN=.

Example

Overview

In the last example, you created the $AIRPORT. format. Suppose you want to add the following airport codes to the format:
airport codes

Step 1: Create a SAS Data Set from the Format

First, you write the $AIRPORT. format as a SAS data set. In the code below, the output data set is named Sasuser.Fmtdata. The SELECT statement is used so that the resulting data set has only the data for the $AIRPORT. format. Without the SELECT statement, the data would have observations for all the formats in the Sasuser.Formats catalog.
proc format lib=sasuser cntlout=sasuser.fmtdata;
   select $airport;
run;
When you use the CNTLOUT= option, SAS creates an output data set that has many variables for storing information about the format. The output data set Sasuser.Fmtdata has 50 rows and 21 columns. In the PRINT procedure below, the VAR statement specifies that only a few of the variables are printed:
proc print data=sasuser.fmtdata (obs=5) noobs;
   var fmtname start end label min max 
       default length fuzz;
run;
Sasuser.Fmtdata
As you can see, the data set contains End and other variables that were not in the original data. When you use the CNTLIN= option, if there is no End variable in the data set, SAS assumes that the Start and End variables have the same value. When you write the format as a data set using the CNTLOUT= option, both variables are in the data set.

Step 2: Edit the Data Set

The next step in updating the format is to edit the data set. You could use PROC SQL or a DATA step to add observations to the data set, or you could add observations using the VIEWTABLE window. Whatever method you choose, you must add values for the FmtName, Start, End, and Label variables. If Start and End are both present, you must enter values for both variables. Otherwise, SAS will return an error. You do not have to add values for the other variables in the data set.

Step 3: Create a Format from the SAS Data Set

Once the data set is edited and saved, you can create a format from the data set using the CNTLIN= option. The following code creates the $AIRPORT. format and then uses FMTLIB to document it:
proc format library=sasuser cntlin=sasuser.fmtdata;
run;

proc format lib=sasuser fmtlib;
   select $airport;
run;
The partial output shown below includes the new airports in the format.
Table 17.5 Partial SAS Output
FORMAT NAME : $AIRPORT LENGTH: 22 NUMBER OF VALUES: 56 MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH: 22 FUZZ: 0
START
END
LABEL (CONT'D)
SYD
END
Sydney, New South Wales
VIE
VIE
Wien (Vienna)
WLG
WLG
Wellington
YQB
YQB
Quebec, QC
YUL
YUL
Montreal, QC
YYC
YYC
Calgary, AB
YYZ
YYZ
Toronto, ON
Tip
For more information about using the CNTLOUT= option, see the SAS documentation for the FORMAT procedure.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.200.106