Task 1: How to Keep NHANES III Data

Here are the steps to keep NHANES III data:

 

Step 1: Keep variables

Because you are interested only in a subset of the variables, you can use the keep option statement to select relevant variables. No output is associated with this procedure, so you will need to check the SAS log file to make sure that the procedure was completed successfully. Additionally, you can use SAS Explorer to see that the new datasets (Lab, Exam, Adult, Youth) are in your WORK library. 

 

Program to Directly Keep Datasets
Statements Explanation
libname NH3 "C:\NHANES III\DATA" ;

Use the libname statement to refer to the data folder.

>data lab;

Use the data step to create a dataset for your laboratory data (lab).

set NH3.lab ( keep =SEQN TCP TGP);

Use the set statement to bring in the laboratory file. Use the keep statement to select the variables of interest.

Info iconIMPORTANT NOTE

Notice that in the keep statement, a variable named "seqn" is included. SEQN stands for sequence number and should be included whenever datasets are appended. SEQN is a unique identifier for each observation (participant) in NHANES. Every time you extract variables from an NHANES III data file, you should include the SEQN variable in your selection. Failing to do so will lead to problems if you want to sort or merge your data files at a later time. See Keep & Merge Module Task 2 for more information on Merging.

 
data exam;

Use the data step to create a dataset for your examination data (exam).

set NH3.exam ( keep =SEQN PEP6G1 PEP6H1 PEP6I1 PEPMNK1R PEP6G3 PEP6H3
PEP6I3 PEPMNK5R BMPBMI MAPF12R MYPC17);

 Use the set statement to bring in the examination file. Use the keep statement to select the variables of interest.

data adult;

Use the data step to create a dataset for your adult questionnaire data (adult).

set NH3.adult ( keep =SEQN HFA8R HAR1 HAR3 HAE1 HAE2 HAE3 HAE5A HAE6 HAE7 HAE9D HAC1C HAF10 HAC1D HSAGEIR
HSAGEU HSSEX DMARETHN SDPPSU6 SDPSTRA6 WTPFEX6 DMPSTAT SDPPHASE);

Use the set statement to bring in the adult questionnaire file. Use the keep statement to select the variables of interest.

 
data youth;

Use the data step to create the dataset for your youth questionnaire data (youth).

set NH3.youth ( keep =SEQN SDPPSU6 SDPSTRA6 WTPFEX6 HSAGEU HSAGEIR DMARETHN DMPSTAT SDPPHASE);

Use the set statement to bring in the laboratory file. Use the keep statement to select the variables of interest.

 

Step 2: Check results

After keeping the variables, it is a good idea to check the contents again to make sure that the datasets were kept with the correct variables in them and with the total number of variables expected.

Highlighted results of the proc contents procedure on the new dataset are:

close window icon Close Window