Hi everyone,
I'm a french machine learning student ans I would really like to use a NHANES dataset to perform linear regression with python, but as the data is made for SAS i want first to create the dataset thanks to SAS.
I'm using the free SAS Studio related to the SAS University Edition, I contacted NHANES to know the steps to follow in order to create the dataset. I did as it was indicated in their e-mails but I still have errors and as I'm totally new to SAS I can't figure out why I'm still struggling with creating the dataset.
Here is the link to the NHANES dataset, followed by the errors I got when I run the SAS code provided (after replacing filename with the location of the data downloaded and saved as .dat on my computer) :
https://wwwn.cdc.gov/nchs/nhanes/nhanes3/datafiles.aspx#core the first Household Adult File in the core data section is the dataset I want
and the errors and warings :
When you SAS is running in the operating system installed on your PC, any file you can find via the Explorer in SAS Studio are also avialable to your SAS Compute Server (the SAS installed on your machine):
With SAS University Edition(UE), your SAS is running in a Linux virtual machine. This works just as if your Linux SAS Compute Server was installed on completely different hardware.
The Virtual machine has virtual disks, but you don't have write access to those. Your computer has a hard drive, but the SAS University Edition virtual machine knows nothing about that. When you set up SAS University Edition, you were given instructions on setting up a shared folder - a location where both the Virtual Machine and your Windows computer could read and write. Because SAS University Edition is deprecated, I don't have access to it, so I can't give you the exact path, but you need to put the .dat file in there and use the Linux path to point to the file.
The SAS code provided is incomplete and includes non-printable characters. To create this dataset:
1. Right-click the link for the .DAT file and choose "Save link as" to save the adult.dat file to your hard drive. I saved mine to the C:\temp directory:
2. Right-click the SAS Code link and save the adult.sas program file, too.
3. Open the adult.sas program file in SAS and make the following changes:
The first part of the program looks like this:
FILENAME ADULT "D:\Questionnaire\DAT\ADULT.DAT" LRECL=3348;
*** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
DATA WORK;
In the first line, change the FILENAME statement to point to the actual location of the adult.dat file. And wanted my dataset to be named adult instead of work, so I also changed the name of the output file in the DATA statement:
FILENAME ADULT "C:\temp\ADULT.DAT" LRECL=3348;
*** LRECL includes 2 positions for CRLF, assuming use of PC SAS;
DATA WORK.ADULT;
Now, use go to the very end of the program file and you'll see something like this:
HAZNOK5R = "Number of BP's used for average K5";
The little box you see is a non-printable character. Delete it and replace it with a RUN; statement so it now looks like this:
HAZNOK5R = "Number of BP's used for average K5";
run;
Save the modified SAS program, then run it. It should work fine now.
Thank you very much for your answer and sorry for mine being late.
Well it's a bit strange. I replaced the strange character by run; If the path is the path to the SAS code file, there is no error but I have an empty array with around 1800 columns/variables and no row.
Now if I replace the path by the path to adult.dat that I saved as a link as you showed me, I have this error :
When you SAS is running in the operating system installed on your PC, any file you can find via the Explorer in SAS Studio are also avialable to your SAS Compute Server (the SAS installed on your machine):
With SAS University Edition(UE), your SAS is running in a Linux virtual machine. This works just as if your Linux SAS Compute Server was installed on completely different hardware.
The Virtual machine has virtual disks, but you don't have write access to those. Your computer has a hard drive, but the SAS University Edition virtual machine knows nothing about that. When you set up SAS University Edition, you were given instructions on setting up a shared folder - a location where both the Virtual Machine and your Windows computer could read and write. Because SAS University Edition is deprecated, I don't have access to it, so I can't give you the exact path, but you need to put the .dat file in there and use the Linux path to point to the file.
Ok thank you so much for the detailed explanations and the pictures, it helped a lot. I'd try to find the path and solve the problem.
Have a nice day,
Yours sincerely,
Geoffrey
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.