Extracting an SAS transport file and saving it to a SAS-accessible library involves three steps:
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 XPDB xport "c:\nhanes\download\demo_b.xpt" ;
libname XPDC xport "c:\nhanes\download\demo_c.xpt" ;
libname XPIB xport "c:\nhanes\download\drxiff_b.xpt" ;
libname XPTB xport "c:\nhanes\download\dr1tot_b.xpt" ;
libname XPTC xport "c:\nhanes\download\dr1tot_c.xpt" ;
libname XPIC xport "c:\nhanes\download\dr1iff_c.xpt" ;
libname XPOC xport "c:\nhanes\download\osq_c.xpt" ;
libname XPSA xport "c:\nhanes\download\dsq1_c.xpt" ;
libname XPSB xport "c:\nhanes\download\dsq2_c.xpt" ;
libname XPSC xport "c:\nhanes\download\DSPI.xpt" ;
libname XPSD xport "c:\nhanes\download\DSII.xpt" ;
libname NH "c:\nhanes\data" ;
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 run.
in =XPDB
out =NH;
;
in =XPDC
out =NH;
;
in =XPIB
out =NH;
run ;
proc
copy
in =XPTB
out =NH;
;
in =XPTC
out =NH;
;
in =XPIC
out =NH;
;
in =XPOC
out =NH;
;
in =XPSA
out =NH;
;
in =XPSC
out =NH;
;
in =XPSD
out =NH;
;
To check the results of your program, open Windows Explorer and go to your C:\NHANES\DATA folder. You should see the downloaded files 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.
data = "C:\NHANES\DATA\demo_b" ;
;
data = "C:\NHANES\DATA\demo_c" ;
;
data = "C:\NHANES\DATA\drxiff_b" ;
;
data = "C:\NHANES\DATA\dr1tot_b" ;
;
data = "C:\NHANES\DATA\dr1tot_c" ;
;
data = "C:\NHANES\DATA\dr1iff_c" ;
;
data = "C:\NHANES\DATA\osq_c";
;
data = "C:\NHANES\DATA\dsq1_c" ;
;
data = "C:\NHANES\DATA\dsq2_c" ;
;
data = "C:\NHANES\DATA\DSPI" ;
;
data = "C:\NHANES\DATA\DSII" ;
;
Click here to view program output
Note that datasets saved in this SAS-accessible library 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.