Extracting a SAS transport file and saving it to a SAS-accessible library involves three steps:
The steps below assume that you are already familiar with extracting and saving datasets from downloaded data files. If you need more detailed instructions about how to extract datasets, please review the Download Data Files Module in the Continuous NHANES Web Tutorial before continuing.
Assign a LIBNAME to each SAS transport file being downloaded. In this example, the transport files, which will be used in sample programs throughout the tutorial, are stored in the DOWNLOAD folder, created in Task 2 of this module. The extension "_b" is used to denote files from the 2001–2002 survey cycle, and the extension "_c" is used to denote files from the 2003–2004 survey cycle.
The XPORT statement tells SAS to extract the data from the transport file, using the XPORT engine, into a SAS-accessible format. Remember to surround the pathnames with quotation marks.
Finally, assign a LIBNAME (NH) to the C:\NHANES\DATA folder. This is where the permanent datasets will be saved on your computer.
libname DEMA xport "c: hanes\download\demo.xpt" ;
libname DEMB xport "c: hanes\download\demo_b.xpt" ;
libname DEMC xport "c: hanes\download\demo_c.xpt" ;
libname PHTA xport "c: hanes\download\phpypa.xpt" ;
libname PHTB xport "c: hanes\download\phpypa_b.xpt" ;
libname PHTC xport "c: hanes\download\l24ph_c.xpt" ;
libname NH "c: hanes\data" ;
If the Documentation, Codebook, and Frequency Tables are separate PDF files (in the earlier survey cycles), use the individual Doc, Codebook, or Freqs link to download (not open) the Documentation, Codebook, or Frequency Tables PDF files and save them in the DOWNLOAD folder one by one.
Use the PROC COPY statement to save the extracted datasets from the transport file to the C:\NHANES\DATA folder. Use IN to denote the folder where the dataset is temporarily being stored and use OUT to denote the library where the dataset will be saved on your computer in a SAS-accessible format.
This procedure must be run for each of the downloaded data files. The output folder is always the same but the input file varies for each statement.
proc copy in =DEMA out =NH;
proc copy in =DEMB out =NH;
proc copy in =DEMC out =NH;
proc copy in =PHTA out =NH;
proc copy in =PHTB out =NH;
proc copy in =PHTC out =NH;
To check the results of your program, open Windows Explorer and go to C:\NHANES\DATA folder. You should see the downloaded files designated as SAS datasets in that folder. You now have these files saved to your computer.
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 the Documentation. By default, variables and their attributes are listed in alphabetic order. Adding the option VARNUM to the PROC CONTENTS, you will have a list of variables in the order of the input statement (the same order as appeared in the PDF Documentation, Codebook and Frequency Tables).
proc data = "C:\NHANES\DATA\phpypa" varnum ;
proc data = "C:\NHANES\DATA\phpypa_b" varnum ;
proc data = "C:\NHANES\DATA\l24ph_c" varnum ;