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. 

Info iconIMPORTANT NOTE

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. 

  1. Open SAS to begin creating your program.
  2. 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.  
  3. 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.
  4. 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 paxraw_c xport 'c:\nhanes\download\paxraw_c.xpt' ;

libname demo_d xport    'c:\nhanes\download\demo_d.xpt' ;
libname paxraw_d xport 'c:\nhanes\download\paxraw_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

proc contents data = demo_c.demo_c;
run ;

proc contents data = paxraw_c.paxraw_c;
run ;

proc contents data = demo_d.demo_d;
run ;

proc contents data = paxraw_d.paxraw_d;
run ;