Task 1: Merge Datasets

Step 1: Run program

Download, open and run the program: SAS Medicare

Program to merge Feasibility and Demographic Files

Explanation of SAS Code to merge Feasibility and Demographic data
Statements Explanation
options ls=120 ps=42 missing=' ' nocenter validvarname=upcase compress=binary; Log/List options. Compress option reduces storage requirements for output datasets.
libname nhanes 'C:\NHANES'; Provides location for reading and saving SAS datasets.
data temp; Creates a temporary SAS dataset, temp.
set nhanes.nhanes_99_00_eligibility_Medicare; Reads in the NHANES 1999-2000 Medicare feasibility data.
proc sort data=temp;
  by SEQN;
run;
Sorts the temp dataset by the variable SEQN.
proc sort data=nhanes.demo;
  by SEQN;
run;
Sorts the NHANES demographic dataset by the variable SEQN.
data nhanes.merg9900_Medicare;
  merge temp
        nhanes.demo;
  by SEQN;

  /*Regroup race_ethnicity as 4 categories*/
      if ridreth1=3 then raceth=1; /*Non-Hispanic White*/
      else if ridreth1=4 then raceth=2; /*Non-Hispanic Black*/
      else if ridreth1=1 then raceth=3; /*Mexican American*/
      else raceth=4; /*Other*/

  label raceth = 'Race/Ethnicity (recode)';
run;

Merges both datasets, by SEQN, which effectively adds variables from the file last referenced to temp.  (Each file contains the same number of observations).
Recodes race/ethnicity variable, RIDRETH1, into 4 categories. New variable is RACETH.
Results are saved in permanent SAS dataset, merg9900_Medicare.sas7bdat.
proc contents data= nhanes.merg9900_Medicare varnum; Lists the contents of SAS dataset. Varnum option prints the list of variables by their position in the dataset.
proc print data= nhanes.merg9900_Medicare (obs=10);
var seqn cms_medicare_match riagendr ridreth1 raceth wtmec2yr;
Prints sample listing of first 10 records with a select set of variables.
proc means data= nhanes.merg9900_Medicare ;
var seqn cms_medicare_match;
Reports the number of observations, the mean, the standard deviation, the minimum value, and the maximum value for two variables in the SAS dataset.

 

Step 2: Check the results.

To check the results of your program, open Windows Explorer and go to the folder referenced in the libname. You should now see merg9900_Medicare..sas7bdat in the folder.

Also, review the SAS log report on the number of observations and variables in the file. This information is also listed in the SAS (.lst) output report for the proc contents.

Highlights from the output:

 

close window icon Close Window to return to module page.