Create SAS-formatted Datasets
Purpose
This module provides instruction on how to create SAS-formatted datasets from the feasibility and NHANES data files.
Task 1: Create SAS-formatted Feasibility File
The feasibility files are public-use text files and will not open directly into the SAS environment. NCHS has provided a sample SAS program to read in the feasibility files and add labels. Using the provided SAS code, you will create a SAS-formatted dataset.
Step 1: Run Sample SAS Program
Download, open and run the sections of the sample SAS program for the linked NHANES-Medicare feasibility file that correspond to this module. This same program will also be used for Modules 7 and 8. The program reads the data and converts it to SAS-formatted files. It is a modified version (including only a subset of variables) of the sample SAS program that can be downloaded from the data linkage FTP site.
Information: A regular left-click may not download the SAS datasets or SAS code correctly. Your browser may try to open and attempt to interpret the contents of the dataset or program. If this happens, right-click the link and save the dataset or program to your hard drive. After the dataset or code has downloaded, use SAS to open and view it.
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. |
* Input File Reference *; filename intext “C:\NHANES\MEDICARE_FEASIBILITY_NHANES_2011_2012.dat”; |
Provides location and name of flat file. |
data nhanes.nhanes_11_12_elig_Medicare; infile intext lrecl=128 ; |
Creates a permanent SAS formatted file with feasibility data for NHANES 2011-2012. |
* Lengths *; input @ 1 SEQN 5. @ 15 CMS_MEDICARE_MATCH 1. ; |
Defines length of variables in SAS dataset. |
* Labels *; label SEQN = ‘NHANES SEQN’ CMS_MEDICARE_MATCH = ‘CMS Medicare Match Status’; |
Assigns descriptive labels to variables in the SAS dataset. |
* Keep *; keep SEQN CMS_MEDICARE_MATCH; run; |
Specifies the variables to include in output SAS dataset. |
proc contents data=nhanes.nhanes_11_12_elig_Medicare varnum; | Lists the contents of the SAS dataset. VARNUM option prints the list of variables by their position in the dataset. |
proc print data=nhanes.nhanes_11_12_eligib_Medicare (obs=10); | Prints sample listing of first 10 records. |
proc means data=nhanes.nhanes_11_12_elig_Medicare; | Reports the number of observations, the mean, the standard deviation, the minimum value, and the maximum value for each numeric variable in the SAS dataset. |
Step 2: Check Results
Check the SAS log of the program to create the NHANES feasibility file from raw data.
Check that NHANES_11_12_ELIG_MEDICARE.sas7bdat has been created.
Check contents for two variables, SEQN and CMS_MEDICARE_MATCH, by opening the SAS dataset, NHANES_11_12_ELIG_MEDICARE.sas7bdat.
Step 1: Run Sample SAS Program
Download, open and run the sections of the sample SAS program for the linked NHANES-Medicaid feasibility file that correspond to this module. This same program will also be used for Modules 7 and 8. This program reads the data and converts it to SAS-formatted files. It is a modified version (including only a subset of variables) of the sample SAS program that can be downloaded from the data linkage FTP site.
Information: A regular left-click may not download the SAS datasets or SAS code correctly. Your browser may try to open and attempt to interpret the contents of the dataset or program. If this happens, right-click the link and save the dataset or program to your hard drive. After the dataset or code has downloaded, use SAS to open and view it.
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. |
* Input File Reference *; filename intext “C:\NHANES\MEDICAID_FEASIBILITY_NHANES_2011_2012.dat”; |
Provides location and name of flat file. |
data nhanes.nhanes_11_12_elig_Medicaid; | Creates a permanent SAS formatted file with feasibility data for NHANES 2011-2012. |
infile intext lrecl=90 ; | Directs input statement to read an external file with logical record length=60. |
input @ 1 SEQN 5. @15 CMS_MEDICAID_MATCH 1.; |
Reads input values from specified columns and informats and assigns them to the corresponding SAS variables. |
* Labels *; label SEQN = ‘NHANES SEQN’ CMS_MEDICAID_MATCH = ‘CMS Medicaid Match Status’ ; |
Assigns descriptive labels to variables in the SAS dataset. |
keep SEQN CMS_MEDICAID_MATCH; |
Specifies the variables to include in output SAS dataset. |
proc contents data=nhanes.nhanes_11_12_elig_Medicaid varnum; | Lists the contents of SAS dataset. VARNUM option prints the list of variables by their position in the dataset. |
proc print data=nhanes.nhanes_11_12_elig_Medicaid (obs=10); | Prints sample listing of first 10 records. |
proc means data=nhanes.nhanes_11_12_elig_Medicaid; | Reports the number of observations, the mean, the standard deviation, the minimum value, and the maximum value for each numeric variable in the SAS dataset. |
Step 2: Check Results
Check the SAS log of the program to create the NHANES feasibility file from raw data.
Check that NHANES_11_12_ELIG_MEDICAID.sas7bdat has been created.
Check contents for two variables, SEQN and CMS_ MEDICAID_MATCH, by opening the SAS dataset, NHANES_11_12_ELIG_MEDICAID.sas7bdat.
Task 2: Create SAS-formatted Datasets from the NHANES Data File
Both the Medicare and Medicaid sample SAS programs include SAS code for creating a SAS-formatted dataset for the NHANES Demographic File. The codes are the same, so running either one will create the same dataset. For more information about the NHANES files, please refer to the continuous NHANES web tutorial.
There are three steps to extracting a SAS transport file and copying it to a permanent library:
- Assign libnames
- Copy to permanent library
- Check results
Step 1: Assign Libname
In your SAS program, you will need to first assign a libname to the folder where you would like to store the permanent NHANES data file, which will be created from the transport file you downloaded in Task 3 of Module 5.
Statements | Explanation |
---|---|
libname XP xport “C:\NHANES\TEMP\demo_g.xpt”; | Assigns the libname XP to the SAS transport file, demo.xpt, stored in the TEMP folder. The XPORT statement tells SAS to extract the data from the transport file using the XPORT engine. |
Step 2: Copy to Permanent Library
Use PROC COPY to copy the extracted data file to the permanent SAS library.
Statements | Explanation |
---|---|
proc copy in=XP out=NHANES; run; |
Copies the extracted dataset from the transport file to the C:\NHANES\DATA folder. |
Step 3: Check Results
To check the results of your program, open Windows Explorer and go to your C:\NHANES\ folder. You should now see DEMO.sas7bdat in the folder. You now have the demographic dataset that will be used in Modules 7 and 8 of this course.