Task 3: How to Open and Save NHANES II Datasets in Permanent Libraries

There are four steps to opening an executable file and saving a SAS dataset in a permanent library:

 

Step 1 Open the Executable File

To execute the file, you double-click on the .EXE file in your temp folder and it will automatically expand. You should now see a file in the TEMP folder with the suffix .TXT indicating it is in ASCII format. The .TXT file will be substantially larger than the original .EXE file.


Step 2 Create and Format SAS Dataset

There are two SAS programs available to create your own SAS dataset: DU5302_F.SAS and DU5302.SAS. The first program includes format statements and procedure whereas the second one does not.  In most cases you will find it helpful to have variable values labeled and thus you will want to use the file DU5302_F.SAS.  This is demonstrated below in Option 1.

Double-click the file in your TEMP folder and it will automatically launch SAS. First you will need to modify the INFILE statement to show the correct path. The path should direct you to the folder where the extracted ASCII file resides. If you followed the steps in Task 1 "Create a Directory" then the path in your INFILE statement should read "C:\NHANES II\TEMP" . Then you will need to add a libname statement. Assign a libname to the place where you'd like the permanent file to be.  Remember this step only creates a temporary SAS dataset (D_5302) that will be saved as a permanent dataset later in Step 3.

 

Info iconIMPORTANT NOTE

As noted in the "Data Structure and Contents" module, Formatted SAS code files are not available for the Chest X-Ray Exam data file, the Electrocardiogram data file, and the Model Gram data file. The example in the option 2 below can be used to download and save these data files. For the 24-Hour Specific Food Item data file, no SAS code files are available and the user must write their own code. It may be helpful to use one of formatted SAS programs provided in this tutorial as a template to create your own code. For the Herpes and Hepatitis data file and the Syphilis Serological Markers data file, SAS transport files are provided, which do not need either of the SAS programs. For these data files, you can follow directions in the Continuous NHANES Web Tutorial module on Download Data Files to download SAS transport files.

Create and Format SAS Dataset
Statements Explanation
libname NH2 "C:\NHANES II\DATA";

Assigns the libname NH2 to the C:\NHANES II\DATA folder. This is where the new dataset will be saved. Remember to surround the pathname in quotation marks.

 

Info iconIMPORTANT NOTE

The tables of code describe the statements used in each program, but are abbreviated to only show a few variables. To view the complete code that includes all the variables, please see the formatted SAS code provided on the NHANES II page.

Option 1 - Open Program Named DU5302_F.SAS
Statements Explanation

PROC FORMAT ;
       ...

VALUE PE0055F
     1 = 'Male'
      2 = 'Female'
     ;

VALUE PE0056F
     1 = 'White'
     2 = 'Black'
     3 = 'Other'
     ;

 VALUE PE0057F
    88 = 'Blank, but applicable'
 
    ; 
      ...

Use the proc format statement and procedure, included in the DU5320_F.SAS program provided, to label all values of categorical variables.

DATA D_5302;

   INFILE "c:\NHANES II\TEMP\DU5302.txt" LRECL = 2000 MISSOVER ;

   LENGTH
     SEQN 8
            ...
     N2PE0055 4
     N2PE0056 4
     N2PE0057 4
            ...
            ;

   FORMAT
    
SEQN 1 - 5
            ...
     N2PE0055 PE0055F.
    
N2PE0056 PE0056F.
    
N2PE0057 PE0057F.
           
...
            ;

   INPUT
     
SEQN 1 - 5
        
    ...
      N2PE0006 6 - 9
     
N2PE0010 10
     
N2PE0011 11
          
 ...
            ;

   LABEL

            ...

       N2PE0055 = "Q4 SEX"        N2PE0056 = "Q5 (SEE DETAILED NOTES) RACE"        N2PE0057 = "Q6 (SEE DETAILED NOTES IN
                   WHAT STATE ..."
           
            ;

Use the data statement to read in the ASCII data file from your existing TEMP folder and create a temporary SAS dataset.

The DATA step includes the INFILE and INPUT statements to read in the data.

The FORMAT statement assigns the formats created in the format procedure and the LABEL statement names each variable.

If you wish to simply read in the data and create the variable names without labeling all the categorical variable values you should open and run the DU5302.SAS program. This program will allow you to read in the ASCII data file from your existing TEMP folder and create a temporary SAS dataset. This is demonstrated below in Option 2. Later on in step 3, this temporary SAS dataset D_5302 will be saved as a permanent dataset.

 

Option 2 - Open Program Named DU5302.SAS
Statements Explanation

DATA D_5302;

   INFILE "c:\NHANES II\TEMP\DU5302.txt" LRECL = 2000 MISSOVER ;

   LENGTH

         SEQN 8

            ...

         N2PE0055 4
         N2PE0056 4
         N2PE0057 4
            ...
            ;

   INPUT
         SEQN 1 - 5
            …
         N2PE0006 6 - 9
         N2PE0010 10
         N2PE0011 11
            ...
            ;