Looking Up Two Variables (Method 2 - Formats) - SAS Programming

You can use the same approach to solve the previous problem by creating another format to associate the prices with the corresponding parts.However,formatted values are always character variables, and you need a numeric variable for PRICE so that you can multiply it by QUANTITY to get TOTAL.One more function (INPUT) and you're done:

Example

PROC FORMAT;
VALUE PARTDESC
123 - 'HAMMER'
232 * 'PLIERS'
333 * 'SAW
432 - 'NAILS7
587 * 'SCREWS1
OTHER * 'NOT ENTERED'?
VALUE PRICE
123 - '25'
232 * '8,50'
333 = '18'
432 = '.01*
587 = '.05'
OTHER - ' ';
RON;
DATA LOOKUP2;
SET INVOICE;
PARTNAME * PUT (PARTJJO,PARTDESC,);
PRICE = INPUT (PUT(PART_NO,PRICE*),5.);
TOTAL = QUANTITY * PRICE;
FORMAT TOTAL DOLLAR6.2;
RUN;
PROC PRINT DATA=LOOKUP2;
TITLE 'Resulting File';
RUN;

The output is shown next:

Output from Example-Looking Up Two Variables (Method 2 - Formats)

Output from Example-Looking Up Two Variables (Method 2 - Formats)

Although the PUT and INPUT functions are described in Chapter 5, "SAS Functions," we briefly explain the use of the INPUT function in this
example.The result of the PUT function is a string which is the character representation of the price of each item (technically called a numeral).

The INPUT function instructs the system to take the value of the first argument (PUT(PART_NO,PRICE.)) and "read it again" according to the informat listed as the second argument (5.).Therefore,the value of PUT (PART_NO,PRICE.) is a character string such as 25.00; the result of the line,INPUT (PUT(PART_NO, PRICE.) ,5.) is then number 25.After reading this paragraph a few times (and maybe taking a walk around the block a few times).


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

SAS Programming Topics