BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PFM151632
Obsidian | Level 7

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;

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 LIBNAME NHANES "C:\NHANES\DATA"
74 libname BMX_H xport "C:\NHANES\DATA\BMX_H.XPT";
_______
22
ERROR: Libref NHANES is not assigned.
ERROR: Error in the LIBNAME statement.
ERROR 22-7: Invalid option name LIBNAME.
 
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
76 libname DEMO_H xport "C:\NHANES\DATA\DEMO_H.XPT";
NOTE: Libref DEMO_H was successfully assigned as follows:
Engine: XPORT
Physical Name: /pbr/biconfig/940/Lev1/SASApp/C:\NHANES\DATA\DEMO_H.XPT
77 libname DEMO_G xport "C:\NHANES\DATA\DEMO_G.XPT";
NOTE: Libref DEMO_G was successfully assigned as follows:
Engine: XPORT
Physical Name: /pbr/biconfig/940/Lev1/SASApp/C:\NHANES\DATA\DEMO_G.XPT
78 proc copy in=BMX_H out=NHANES;
79 run;
 
ERROR: Libref NHANES is not assigned.
NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 467.03k
OS Memory 31144.00k
Timestamp 04/17/2021 01:04:56 PM
Step Count 594 Switch Count 0
Page Faults 0
Page Reclaims 57
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
NOTE: The SAS System stopped processing this step because of errors.
 
 
80 proc copy in=BMX_G out=NHANES;
81 run;
 
ERROR: Libref NHANES is not assigned.
NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 579.15k
OS Memory 31144.00k
Timestamp 04/17/2021 01:04:56 PM
Step Count 595 Switch Count 0
Page Faults 0
Page Reclaims 48
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
NOTE: The SAS System stopped processing this step because of errors.
 
 
82 proc copy in=DEMO_H out=NHANES;
83 run;
 
ERROR: Libref NHANES is not assigned.
NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 579.15k
OS Memory 31144.00k
Timestamp 04/17/2021 01:04:56 PM
Step Count 596 Switch Count 0
Page Faults 0
Page Reclaims 49
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
NOTE: The SAS System stopped processing this step because of errors.
 
 
84 proc copy in=DEMO_G out=NHANES;
85 run;
 
ERROR: Libref NHANES is not assigned.
NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 579.15k
OS Memory 31144.00k
Timestamp 04/17/2021 01:04:56 PM
Step Count 597 Switch Count 0
Page Faults 0
Page Reclaims 48
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
NOTE: The SAS System stopped processing this step because of errors.
86
87 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
99
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
PFM151632
Obsidian | Level 7

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. 

 

PFM151632_0-1618870078655.png

 

then when I initiate the proc copy I have an error message

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 libname ALQ_G '/home/u47547945/NHANES';
NOTE: Libref ALQ_G refers to the same physical library as NHANES.
NOTE: Libref ALQ_G was successfully assigned as follows:
Engine: V9
Physical Name: /home/u47547945/NHANES
74 run;
75 proc copy in=ALQ_G out= NHANES/ALQ_G; run;
_
22
200
 
ERROR 22-322: Syntax error, expecting one of the following: ;, ACCEL, ALTER, CLONE, CONSTRAINT, DATECOPY, ENCRYPTKEY, FORCE, IN,
INDD, INDEX, INLIB, MEMTYPE, MOVE, MT, MTYPE, NOACCEL, NOCLONE, OUT, OUTDD, OUTLIB, OVERRIDE, PROTECT, PW.
 
ERROR 200-322: The symbol is not recognized and will be ignored.
 
NOTE: Statements not processed because of errors noted above.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 523.15k
OS Memory 30120.00k
Timestamp 04/19/2021 10:09:22 PM
Step Count 200 Switch Count 0
Page Faults 0
Page Reclaims 56
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
NOTE: The SAS System stopped processing this step because of errors.
76
77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
89
 
Is there any guidance document that I could use for step by step approach ?
Tom
Super User Tom
Super User

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;
PFM151632
Obsidian | Level 7

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. 

Tom
Super User Tom
Super User

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;

 

PFM151632
Obsidian | Level 7

Thank you ! it worked.

PFM151632
Obsidian | Level 7
I found the solution. resolved
Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 4238 views
  • 3 likes
  • 3 in conversation