BookmarkSubscribeRSS Feed
moomoo11
Calcite | Level 5

Hi! I am a grad student trying to analyze some food frequency questionnaires using an existing tool and publicly available codebook/SAS macro. I have only used SAS a handful of times and never for something like this.

 

Basically, what I am trying to do (for starters) is delete the data on the SAS file I downloaded from NHANES website so I can put my data in instead. I can't even figure out how to do that. How do I delete the data in the following SAS file without messing up anything else? I coded by data in a separate excel sheet the same way the codebook (see below) codes it, but am stuck on deleting all of the rows of sample rows (over 600 samples) in the below file. My study only has 37.

 

Here is a link to the codebook: https://wwwn.cdc.gov/Nchs/Nhanes/2003-2004/FFQRAW_C.htm

Here is a link to the SAS file I am trying to use: https://wwwn.cdc.gov/Nchs/Nhanes/2003-2004/FFQRAW_C.XPT

 

Thanks so much in advance!

2 REPLIES 2
Tom
Super User Tom
Super User

If you have data in an Excel you can just read that into SAS. You could use PROC IMPORT or just use the new XLSX libref engine.

Not sure why you would need to reference any other SAS dataset to do that.

SuryaKiran
Meteorite | Level 14

First you need to convert the XPT file to SAS Dataset. 

 

/* Convert XPT to SAS Dataset */
libname SAS_DS 'E:\SASUniversityEdition\SandBox\Datasets';
libname xptfile xport 'E:\SASUniversityEdition\SandBox\Files\Input\FFQRAW_C.XPT' access=readonly;

proc copy inlib=xptfile outlib=SAS_DS;
run;

There are several ways to delete rows from a dataset depending on how you want to delete them, one way is as follows

PROC SQL;
delete from SAS_DS.FFQRAW_C
where WTS_FFQ is null;
quit;

Also there are several ways to insert data like: 


/* Insert values manually */
proc sql;
insert into SAS_DS.FFQRAW_C
values (1,2,3,4,.....)
values (2,3,4,5,5....);
quit;

/* Insert values from existing table */
proc sql;
insert into SAS_DS.FFQRAW_C
select * from another_table;
quit;
Thanks,
Suryakiran

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 839 views
  • 0 likes
  • 3 in conversation