A Two-way Lookup Table - SAS Programming

For this example you have two SAS data sets. DAILY contains subject ID number, YEAR ,SEASON, and RAINFALL;TEMP contains TEMPER (mean temperature), YEAR, and SEASON.

A Two-way Lookup Table

Here are some sample data: You want to read the DAILY data set, look up the temperature in the TEMP data set corresponding to the matching YEAR andSEASON, and create a new data set called COMBINED.Here is the code:

Example

PROG SORT DATA=TEMP;
BY YEAR SEASON;
RON;
PROC SORT DATA=DAILY;
BY YEAR SEASON;
RUN;
DATA COMBINED;
MERGE DAILY (IN^INDAILY) TEMP;
BY YEAR SEASON;
IF INDAILY;
RUN;
PROC PRINT DATA=COMBINED;
TITLE 'Listing of the Combined Data Set';
RUN;

The resulting output is:

Output from Example - A Two-way Lookup Table

Output from Example - A Two-way Lookup Table
By match-merging the two data sets on the variables YEAR and SEASON, you are able to associate the mean temperature with the amount of rainfall for each year-season combination.In this example, bit's ambiguous as to which data set serves as the lookup table and which one serves as the data. Usually, a lookup table has one record for each unique value of the lookup variable.In this case, they both do.

Problems

  1. You have company data in three SAS data sets. Data set EMPLOY contains ID (employee number),GENDER,and DOB (date of birth).Data set PARTS contains PART_NO and PRICE.Data set SALES contains ID(employee number),TRANS( trans action number), PART_NO,and QUANTITY (for each sales call completed).You want to generate reports which contain:
  2. a. a listing, sorted by ID,showing ID, the transaction number, and the total sales for each transaction.
    b. a summary showing the total sales for each employee.
    c. a summary showing the total company sales for each GENDER.

    Problems

    Here are some sample data values from each data set: Note that data set EMPLOY is already sorted in ID order and data set PARTS is already sorted in PART_NO order.Hints: Since this is a difficult problem, let us suggest a few hints.First,merge the PARTS and SALES data sets to create a new data set (call it NEWSALES) that contains ID,TRANS,and TOTAL (PRICE*QUANTITY).Notice that there are some part numbers in the PARTS file that were not sold and need not be included in the listing.This is enough for part A.

    Next, merge the NEWSALES data set just created with the EMPLOY data set so that GENDER information can be added.Consider using PROC MEANS to compute totals by ID for part B,and totals by GENDER for part C.You can accept output from PROC MEANS or, if you want to be fancy,create a report from an output data set created by PROC MEANS (discussed in Chapter 10, "PROC MEANS and PROC UNIVARIATE"). We show both solutions.

  3. You have clinical data in a SAS data set called CLINICAL which contains information on patient visits.Included in the data set are patient ID, DATE,BILLING (billing number),and DX(diagnosis code).You also have a list of DX codes and their descriptions.Using the following CLINICAL data and the list of DX codes and descriptions,create a new data set,NEW,which contains all the variables in CLINICAL plus a new variable (DESCRIP) which contains the DX description.
  4. Use PROC FORMAT and a PUT function as in to solve this problem.

    A Two-way Lookup Table


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

SAS Programming Topics