10-12-2015 10:58 PM
I am wondering if anyone knows how to input NHAMCS data into SAS. For a project, I am to reproduce Table 1 from the following article: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3338876/
I am having trouble inputting the dataset, and figuring out how to merge 2003-2009 data. The SAS input, format, and label codes are located here for all years: ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHAMCS/sas
Does anyone know what code or macros I would have to use? I really have no idea where to start. Thanks in advance!
10-13-2015 11:30 AM - edited 10-13-2015 02:40 PM
It appears that CDC is being its typically partially helpful self.
You will need to download the data sets, which are apparently elsewhere. There is a chance that there may be SAS data as well as text files to read. if so, get the SAS data sets. Otherwise you will need to write a data step to read the text versions. That would be something like:
Libname YourLib "your path to your library"; filename Data2009 "path to the 2009 data"; data yourlib.data2009; infile data2009 <appropriate options for LRECL=10000 or similar likely needed>; <The code from the 09INP.txt file goes here OR an %INCLUDE pointing to that file> <the 09LAB.txt or an %include goes here> ;
run; The FOR.TXT files have formats, which will also document the values of the variable.
And a section of code to associate variables with the format. That part of the code could
be in the data step to read the file.
BEFORE you combine any data sets you need to make sure that the coding of any variables in common is the same. If they aren't you'll have to account for that.
The basic approach would be to APPEND the data:
set yourlib.data2003 yourlib.data2004 ... yourlib.data2009;
HOWEVER you still have at least one major stumbling block: Weights. I do not see a variable that looks like the final weight to use for analysis. Also depending on the sample type (pretty much anything other than a simple random sample) you need the sample design and will almost certainly need to use the SURVEY procs, Surveyfreq, Surveymeans, surveyreg, surveylogisitic for analysis.
10-13-2015 09:50 PM
10-13-2015 09:51 PM
Sorry, I forgot to include the code
libname nh "E:\BIS 679\NHAMCS"; %Let dir=E:\BIS 679\; %macro dataset; %do i=03 %to 09; %let year=&i; *formats; %include "&dir.NHAMCS\Formats\ed&yearfor.txt"; *import dataset; data ed&year; infile "&dir.NHAMCS\ed&.txt" DSD MISSOVER LRECL=999; %include "&dir.NHAMCS\Inputs\ed&yearinp.txt"; %include "&dir.NHAMCS\Labels\ed&yearlab.txt"; run; %end; %end; %end; %mend dataset; %dataset; run;
10-14-2015 01:03 AM
You are referencing macro variables that you did not define.
Most likely because you did not add a period to let SAS know where the stop the search for the macro variable name.
So this line
Should probably be changed to this.
10-13-2015 06:05 PM
Just as an addendum:
This readme tells you pretty much what to do:
You've got the data as self-extracting zip files here (from the readme file):
This data are text files.
You then got the SAS code to read this data into SAS here:
There are also quite a few other readme.txt files explaining per year what to do for this year. You need to read these "readme".