How to Extract and Save Data Files
Now you are ready to start working with the SAS transport files. Your first step is to extract and save the data files in their analytic form.
This tutorial assumes that you are familiar with the SAS programming language. The code below will be entered into your SAS editor.
To extract and save data files, you will need to:
Assign a library name (LIBNAME) to each SAS transport file being downloaded
This example uses the transport files that you downloaded and stored in the DOWNLOAD folder in Task 2, Step 1 of this module. These files will be used in sample programs throughout the tutorial. The extension “_c” is used to denote files from the 2003-2004 survey cycle and the extension “_d” is used to denote files from the 2005-2006 survey cycle.
The XPORT statement tells SAS to extract the data from the transport file, using the XPORT engine, into a SAS-accessible format. This new data file will have a .sas extension.
- Open SAS to begin creating your program.
- Assign each transport file a library name, or LIBNAME, that mimics the transport file name. For example, “demo_c” is the LIBNAME for the demo_c transport file.
- Include the path where the export file is saved. Remember to surround the pathnames with quotation marks. Single and double quotation marks have the same function in SAS.
- Next, assign a LIBNAME (nhanes) to the C:\NHANES\DATA folder. Once you finalize your analytic dataset, we will permanently save it to the ‘nhanes’ library. In the next Task, you will learn how to merge and append the six datasets to create a permanent dataset that can be used for analysis. This permanent dataset will be saved in the DATA folder.
Sample Code
libname demo_c xport 'c:\nhanes\download\demo_c.xpt' ;
libname paq_c xport 'c:\nhanes\download\paq_c.xpt' ;
libname paqiaf_c xport 'c:\nhanes\download\paqiaf_c.xpt' ;
libname demo_d xport 'c:\nhanes\download\demo_d.xpt' ;
libname paq_d xport 'c:\nhanes\download\paq_d.xpt' ;
libname paqiaf_d xport 'c:\nhanes\download\paqiaf_d.xpt' ;
libname nhanes 'c:\nhanes\data' ;
Check your results
To check the results of your export, open the SAS Explorer to check the contents of the SAS Environment. Double-click “Libraries” to see your newly created libraries. Next double-click one of the libraries to see the SAS accessible dataset.
You can also run a PROC CONTENTS statement in SAS to check that your dataset contains the correct number of observations and variables based on information in the documentation.
Note that datasets saved in these SAS-accessible libraries can be used between SAS sessions. This is in contrast to a dataset used within a SAS session, which is deleted when the session ends.
Sample Code
data = demo_c.demo_c;
;
data = paq_c.paq_c;
;
data = paqiaf_c.paqiaf_c;
;
data = demo_d.demo_d;
;
data = paq_d.paq_d;
;
data = paqiaf_d.paqiaf_d;
;