Using a SAS Data Set to Create a Numeric Format - SAS Programming

The previous technique can also be used to create a numeric format. In this example, you have a long list of numeric codes and country names, and you want to create a format assigning a country name to each of the numeric codes.You create the CNTLIN data set in one step and (cleverly) use the variable names START and VALUE for the numeric codes and the country names respectively. Here is the program:

Example

DATA COUNTRY;
RETAIN FMTNAME 'COUNTRY'
TYPE 'N';
INPUT START 1-2
LABEL $ 3-15;
DATALINES?
01UNITED STATES
02FRANCE
03ENGLAND
04SPAIN
05GERMANY
PRCK: FORMAT CNTLIN=COUNTRY FMTLIB;
RUN;

Since you do not use the format you create to format actual data, the only output you have is from the FMTLIB option. Here it is:

Output from Example - Using a SAS Data Set to Create a Numeric Format

Output from Example - Using a SAS Data Set to Create a Numeric Format

Although control data sets seem complicated at first,when the alternative is writing hundreds (or thousands) of assignment statements,we strongly recommend you consider using them.

Problems

  1. You have a SAS data set containing survey data which is coded as follows: Write the necessary statements to create SAS formats for these variables. Also, write the FORMAT statement you would include in the DATA step to assign the formats you have created to each of the variables listed.
  2. Output from Example - Using a SAS Data Set to Create a Numeric Format

  3. You have a collection of raw data (in external file ZIP) with the following file layout:Use this raw data file to create a character format called $ZIPCODE which will assign town names to ZIP codes.
  4. Output from Example - Using a SAS Data Set to Create a Numeric Format

    Here are some sample data:

    08822Flemington
    08903New Brunswick
    78028Kerrville

    Hint: Use the CNTLIN feature of the FORMAT procedure.

  5. You have a SAS data set INVENTRY which contains the numeric variable PART_NO (part number) and the character variable DESCRIPT (part description.) Use this existing data set to create a format called PARTS which associates the part numbers with the descriptions.
  6. Here is part of data set INVENTRY:

    Output from Example - Using a SAS Data Set to Create a Numeric Format


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics