Looking Up Two Variables (Method 1 - Merging) - SAS Programming

Let's extend by looking up a unit price as well as a product description,then multiplying the price by the quantity ordered to obtain a value for TOTAL.First,include PRICE (a numeric variable) in the PARTS data set:

The program to look up the part description and price is shown next:

Looking Up Two Variables (Method 1 - Merging)

Example

PROC SORT DATA=INVOICE;
BY PART_NO;
RON?
DATA LOQKUP1;
MERGE INVOICE (IK*INCLUDE) PARTS;
BY PART_NO;
IF INCLUDE - 1;
IF PARTNAME=* ' THEN PARTNAME-'NOT ENTERED';
TOTAL * QUANTITY * PRICE}
FORMAT TOTAL DOLLARS.2;
RUN?
PROC PRINT DATA=LOOKUPly
TITLE 'Resulting File'?
RUN;

Output from the PROC PRINT is shown next:

Output from Example-Looking Up Two Variables (Method 1 - Merging)

Output from Example-Looking Up Two Variables (Method 1 - Merging)

The first step in this example, as it was in , is to sort the INVOICE data set by PART_NO.(Remember that the PARTS data set was previously sorted.)As was done before,the IN= option is used to output only those observations in the merged data set for which an INVOICE is written and missing values for PARTNAME are replaced with the text NOT ENTERED.

The total price (TOTAL) for each item is simply QUANTITY times (unit)PRICE.Finally, the DOLLAR6.2 format is applied to TOTAL so that it prints with dollar signs and commas.Since part number 999 made by the TOPHAT company is not in the PARTS data set,there is a missing value for PRICE,and therefore for TOTAL as well.


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

SAS Programming Topics