Task 2: How to Merge NHANES I Data

Here are the steps to keep NHANES I data:

 

Step 1 Sort data files by SEQN

The first step in merging data is to sort each of the data files by a unique identifier.  In NHANES I data, this unique identifier is known as the sequence number (SEQN). NHANES I uses SEQN to identify each sample person, so SEQN is the variable you must use to merge data files. To ensure that all observations are ordered in the same way in each data file, you need to sort each data file by the SEQN variable. Use the proc sort procedure in SAS to sort the data.

 

 

Step 2 Merge data by SEQN

After sorting the data files, you can continue merging the data using the merge statement. Remember that you will always merge on a unique identifier — in this case, the SEQN variable. This is demonstrated in the table below.

 

Step 3 Check the results

After you have merged the data files, it is advisable that you check the contents again to make sure that the files merged correctly. Use the proc contents procedure to list all variable names and labels; use the proc means procedure to check the number of observations for each variable as well as missing, minimum, and maximum values.

 

Program to Merge Data and Check Contents of Data
Statements Explanation
proc sort data =biochem;

    by SEQN;

Use the proc sort procedure and by statement to sort the biochemistry data by SEQN.

proc sort data =exam;

    by SEQN;

Use the proc sort procedure and by statement to sort the examination data by SEQN.

proc sort data =adulthistory;

    by SEQN;

Use the proc sort procedure and by statement to sort the adult history questionnaire data by SEQN.

proc sort data =anthro;

    by SEQN;

Use the proc sort procedure and by statement to sort the anthropometric data by SEQN.
proc sort data =genmedical;

    by SEQN;

Use the proc sort procedure and by statement to sort the general medical history supplement data by SEQN.

data DEMO1_NH1;

Use the data step to name the new dataset that will contain the merged files (DEMO_NH1).

merge
BIOCHEM
EXAM
ADULTHISTORY
ANTHRO
GENMEDICAL;
by SEQN;

Use the merge statement to merge data from the five data files by their linking variable - SEQN.

proc contents data =DEMO1_NH1 varnum ;

Use the proc contents procedure to list contents of the DEMO1_NH1 data — the new merged dataset.

Use the varnum option to order the listed variables according to their positions in the dataset.

proc means data =DEMO1_NH1 N Nmiss min max maxdec = 2;

Use the proc means procedure to show the mean, number of missing values, minimum and maximum values for the variables in the merged dataset (DEMO1_NH1).

 

Highlighted results of this program:

 

 

 

close window icon Close Window