I keep having an issue to run my program. There is an error stating that my libref is not assigned. is it because of the format of the data downloaded from NHANES (sas viewer; xpt)? see below. thanks for any guidance
LIBNAME NHANES "C:\NHANES\DATA\BMX_H.XPT"
libname BMX_H xport "C:\NHANES\DATA\BMX_H.XPT";
libname BMX_G xport "C:\NHANES\DATA\BMX_G.XPT";
libname DEMO_H xport "C:\NHANES\DATA\DEMO_H.XPT";
libname DEMO_G xport "C:\NHANES\DATA\DEMO_G.XPT";
proc copy in=BMX_H out=NHANES;
run;
proc copy in=BMX_G out=NHANES;
run;
proc copy in=DEMO_H out=NHANES;
run;
proc copy in=DEMO_G out=NHANES;
run;
proc sort data=DEMO_G;
BY SEQN;
PROC SORT DATA=DEMO_H;
BY SEQN;
PROC SORT DATA=BMX_G;
BY BMXBMI;
LIBNAME NHANES "C:\NHANES\DATA"
This won't work. There has to be a semi-colon on the end of the LIBNAME statement for this to work.
LIBNAME NHANES "C:\NHANES\DATA"
This won't work. There has to be a semi-colon on the end of the LIBNAME statement for this to work.
Thank you, I finally succeeded to create my library NHANES.
Now I would like to xport my different files (e.g. ALQ_01 ALQ_02 etc...) to NHANES library and then proc copy but I do not succeed to create the subfolders in NHANES library.
then when I initiate the proc copy I have an error message
Libraries don't have subfolders.
What are you trying to do?
Are you trying to copy from a series of transport files into a single directory with all of the individual SAS datsets in it?
libname NHANES 'some path';
libname ALQ_G xport 'some filename';
proc copy inlib=alq_g out=nhanes; run;
libname ALQ_F xport 'some filename';
proc copy inlib=alq_f out=nhanes; run;
I am trying to Convert .XPT to SAS Datasets after having uploaded my datasets in my folders and copy them in the library. I have created a folder NHANES in library but the datasets in xpt format that I tried to copy in this NHANES library are copied in the library as individual xpt files.
The description of the actions taken is still a little confusing. It sounds like you copied a bunch of XPT files into a folder and you want to convert those XPT files into datasets in the same folder.
A SAS libref will point to a directory when using normal (BASE) engine. But when using the XPORT engine it needs to point to file. Each XPT file could contain multiple datasets, but I suspect that NHANES is just publishing one member per file. So the code I posted before should work. You just need to repeat it for every file you want to convert.
Point a libref to the place where you want to write the SAS datasets.
Then for each XPT file point a libref at the file using the XPORT engine and run PROC COPY to copy all of the members from the XPT file into the target libref.
If you have the list of filenames in a dataset you can use it to generate the code. Otherwise just copy and paste the code and change the filename used each time.
NHANES published many dataset for each WAVE. The base name for a dataset stays the same and the suffix changes for each wave. So this link, https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.XPT, is to the demographics data for the 2017-2018 wave and this link,https://wwwn.cdc.gov/Nchs/Nhanes/2015-2016/DEMO_I.XPT , is for the same data for the previous 2015-2016 wave.
So to copy from those two files into dataset in the NHANES libref you would use code like this:
libname NHANES '/home/u47547945/NHANES';
libname DEMO_I '/home/u47547945/NHANES/DEMO_I.XPT';
proc copy inlib=demo_i out=nhanes; run;
libname DEMO_J '/home/u47547945/NHANES/DEMO_J.XPT';
proc copy inlib=demo_j out=nhanes; run;
...
But it is probably simpler to just reuse the name libref to point the transport file so there is less to modify as you replicate the code.
libname FROM '/home/u47547945/NHANES/DEMO_I.XPT';
proc copy inlib=from out=nhanes; run;
libname FROM '/home/u47547945/NHANES/DEMO_J.XPT';
proc copy inlib=from out=nhanes; run;
Thank you ! it worked.
The libnames that worked show you more about what is wrong than the ones that failed.
75 libname BMX_G xport "C:\NHANES\DATA\BMX_G.XPT"; NOTE: Libref BMX_G was successfully assigned as follows: Engine: XPORT Physical Name: /pbr/biconfig/940/Lev1/SASApp/C:\NHANES\DATA\BMX_G.XPT
Your SAS session is running on UNIX so it cannot use Windows style directory names. Most likely SAS is actually running on a different machine than where you have that C: drive mounted.
Place the data on a directory that exists on the Unix machine where SAS is running and use the right path that points to that folder in your SAS code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.