How to get NHAMCS data into R?

Viewed 593

I'm trying to work with a colleague on the CDC's NHAMCS 2011-2014 data, however he has SAS and I only have R (because it's free).

The data is supposed to be available here: https://www.cdc.gov/nchs/ahcd/ahcd_questionnaires.htm

However, it is formatted for SAS, SPSS, or STATA according to the documentation. The files are broken up in ways I've never seen before. I've previously been able to download files into R, but when I download the zip files here and try to then open them in R I get strings of meaningless characters and no column headers.

In the past I had successfully used the following code to get NHANES data:

tf <- tempfile()
download.file("https://wwwn.cdc.gov/Nchs/Nhanes/2013-2014/DEMO_H.XPT", tf, mode="wb")                                          
DEMO <- read.xport(tf)

Is there a way to rework this for NHAMCS 2011-2014?

2 Answers

Those files are distributed in either self-extracting compressed formats (possibly specific to Windows) or in ZIP fomats. When I expanded the 2015 zip file it became 55MB froma a starting size of 2.3 MB. The file is in a fixed field format and R has a read.fwf function that will handle that. Furthermore, most of the US Public Use Datasets have access methods documented by @AnthonyDamico although this seems to be one he missed. The SAS input statements are at: ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Dataset_Documentation/NHAMCS/sas/ . Nonetheless, his SAScii package will undoubtedly be useful once you get together the three years data and their associated SAS input programs.

Related