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

tianerhu_1-1636574009719.png

 

I download the file from :

https://wwwn.cdc.gov/Nchs/Nhanes/Search/DataPage.aspx?Component=Questionnaire&Cycle=1999-2000

 

and then transform this rhq_c.xpt to SAS data set using the following code :

filename xptIn url "C:\SAS data and program\data\data set from NHANES/DEMO_I.xpt"; 
libname xptIn xport;

* Download and inport the xpt file and save as a temporary SAS dataset in your work directory *;
* using Proc COPY *;
proc copy in=xptIN out=work;
run;

* or using a data step *;
data demo_i;
  set xptIn.demo_i;
run;

* To save a permanent SAS dataset *;
** TutorialUser: update this libname to reference a directory on your hard drive where you want to save the dataset **;
libname mydata "C:\SAS data and program\data\data set from NHANES";

data mydata.demo_i;
  set xptIn.demo_i;
run;

and finally, I want to check the variables using the following code :

proc contents data = mydata.rhq_c;
run;

and the output like this:

tianerhu_2-1636574329601.png

why ? please give me  a help.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

DEMO_I is the demography XPT file, which is not listed in your initial file link.

Are you pointing to the demographic file or the RHQ file? Did you update the code to reflect the file name of the XPT file downloaded?

 

It works when using the RHQ file but make sure that the case is correct. Seems like it's all upper case. I tested this in On Demand and it worked. 

 

libname xptIn xport "/home/fkhurshed/Demo1/RHQ.XPT"; 
libname demo '/home/fkhurshed/Demo1';
* Download and inport the xpt file and save as a temporary SAS dataset in your work directory *;
* using Proc COPY *;
proc copy in=xptIN out=demo;
run;

proc contents data=demo.RHQ;
run;

 

View solution in original post

9 REPLIES 9
Reeza
Super User

The data set referenced in PROC CONTENT isn't the same one shown in your code.
Are you sure you're referencing the correct data set?

 


@tianerhu wrote:

tianerhu_1-1636574009719.png

 

I download the file from :

https://wwwn.cdc.gov/Nchs/Nhanes/Search/DataPage.aspx?Component=Questionnaire&Cycle=1999-2000

 

and then transform this rhq_c.xpt to SAS data set using the following code :

filename xptIn url "C:\SAS data and program\data\data set from NHANES/DEMO_I.xpt"; 
libname xptIn xport;

* Download and inport the xpt file and save as a temporary SAS dataset in your work directory *;
* using Proc COPY *;
proc copy in=xptIN out=work;
run;

* or using a data step *;
data demo_i;
  set xptIn.demo_i;
run;

* To save a permanent SAS dataset *;
** TutorialUser: update this libname to reference a directory on your hard drive where you want to save the dataset **;
libname mydata "C:\SAS data and program\data\data set from NHANES";

data mydata.demo_i;
  set xptIn.demo_i;
run;

and finally, I want to check the variables using the following code :

proc contents data = mydata.rhq_c;
run;

and the output like this:

tianerhu_2-1636574329601.png

why ? please give me  a help.


 

Tom
Super User Tom
Super User

If the file is on your C drive why are you using the URL engine?

libname xptIn xport "C:\SAS data and program\data\data set from NHANES\DEMO_I.xpt"; 

* Create work datasets using Proc COPY *;
proc copy in=xptIN out=work;
run;

Note that the XPORT libref engine is one of the few SAS engines that can actually handle reading from the URL filename engine, so you do not really need to save a copy of the XPT file.  Just save the SAS dataset.

filename url url "https://wwwn.cdc.gov/Nchs/Nhanes/2015-2016/DEMO_I.XPT";
libname url xport;
proc copy inlib=url outlib=work;
run;

 

tianerhu
Pyrite | Level 9
This result is the same as mine before. 

tianerhu_0-1636580926757.png

 

 

Reeza
Super User

DEMO_I is the demography XPT file, which is not listed in your initial file link.

Are you pointing to the demographic file or the RHQ file? Did you update the code to reflect the file name of the XPT file downloaded?

 

It works when using the RHQ file but make sure that the case is correct. Seems like it's all upper case. I tested this in On Demand and it worked. 

 

libname xptIn xport "/home/fkhurshed/Demo1/RHQ.XPT"; 
libname demo '/home/fkhurshed/Demo1';
* Download and inport the xpt file and save as a temporary SAS dataset in your work directory *;
* using Proc COPY *;
proc copy in=xptIN out=demo;
run;

proc contents data=demo.RHQ;
run;

 

tianerhu
Pyrite | Level 9

now I can see how many variables using contents procedure. But ,  why does a message appear?

 

tianerhu_0-1636587186409.png

The following is my code :

libname xptIn xport "C:\SAS data and program\data\data set from NHANES/RHQ.XPT";
libname demo "C:\SAS data and program\data\data set from NHANES";
* Download and inport the xpt file and save as a temporary SAS dataset in your work directory *;
* using Proc COPY *;
proc copy in=xptIn out=demo;
run;

proc contents data=demo.RHQ;
run;

and the following is information from log:

441  libname xptIn xport "C:\SAS data and program\data\data set from NHANES/RHQ.XPT";
NOTE: Libref XPTIN was successfully assigned as follows:
      Engine:        XPORT
      Physical Name: C:\SAS data and program\data\data set from NHANES\RHQ.XPT
442  libname demo "C:\SAS data and program\data\data set from NHANES";
NOTE: Libref DEMO refers to the same physical library as MYDATA.
NOTE: Libref DEMO was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\SAS data and program\data\data set from NHANES
443  * Download and inport the xpt file and save as a temporary SAS dataset in your work directory
443!  *;
444  * using Proc COPY *;
445  proc copy in=xptIn out=demo;
446  run;

NOTE: Input library XPTIN is sequential.
NOTE: Copying XPTIN.RHQ to DEMO.RHQ (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 3517 observations read from the data set XPTIN.RHQ.
NOTE: The data set DEMO.RHQ has 3517 observations and 90 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


447
448  proc contents data=demo.RHQ;
449  run;

NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


 

Reeza
Super User
What triggered the error?
ballardw
Super User

Your code that you have shared does not involve any file name ending in "RHQ C.xpt" that appears in your error message.

If you copied anything for file names you might want to delete and TYPE them just in case you have a hidden character that is getting interpreted as C (or whatever, the font in the image is too small for me to read easily).

Or is occurring from code you haven't managed to share yet.

tianerhu
Pyrite | Level 9

Thank you all for your help.

I have find the error.

using slash instead of backslash .

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1272 views
  • 0 likes
  • 4 in conversation