Simple Table Lookup (Method 2 - Formats) - SAS Programming

You can accomplish the same goal as the previous example did by using a format and a PUT function instead of merging the PARTS data set and the INVOICE data set.The code looks like this:

Example

PROC FORMAT;
VALUE PARTDESC
123 * 'HAMMER'
232 = 'PLIERS'
333 = 'SAW
432 * 'NAILS'
587 = 'SCREWS'
OTHER - 'NOT ENTERED';
RUN;
DATA LOOKUP2;
SET INVOICE;
PARTNAME - PUT (PART_NO,PARTDESC.);
RUN?
PROC PRINT DATA=LOOKUP2;
TITLE 'Resulting File';
RUN;

The resulting listing is identical to the last output except that the order of the observations is different since the technique shown here did not require the INVOICE data set to be sorted by
PART_NO.

This has two advan tages:first,you save some CPU time;second,you maintain the INVOICE data set in its original order (by invoice number for example).As you will see in if you have a large number of part numbers and descriptions where creating the desired format would be tedious, you can create the format by reading part numbers and descriptions from a raw file or from a S AS data set,and requesting the SAS System to create the format for you using what is called a control data set.


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

SAS Programming Topics