1

I am attempting to read NHANES III, a publicly available epidemiological dataset available from: https://wwwn.cdc.gov/nchs/nhanes/nhanes3/datafiles.aspx#core

It is not clear how to do this but they do provide a data file and a SAS file:

https://wwwn.cdc.gov/nchs/data/nhanes3/1a/lab.dat

https://wwwn.cdc.gov/nchs/data/nhanes3/1a/lab.sas

The data file does not seem to be a conventional SAS export format. Here is a sample of the header:

00003038722311121202610404037061400.6411144120 000001523001737.58001735.14003702.83 000000000 000000000000003046003475.15003470.28007405.66 000000000

But the SAS file seems to describe its format with LENGTH, FORMAT, INPUT and LABEL headers:

FILENAME LAB "D:\LAB\DAT\LAB.DAT" LRECL=1979;
*** LRECL includes 2 positions for CRLF, assuming use of PC SAS;

DATA WORK;
  INFILE LAB MISSOVER;


LENGTH
    SEQN      4
    DMPFSEQ   5
    DMPSTAT   3
    ......
 FORMAT
    DMPPIR   Z6.3
    WTPFQX6  Z9.2
    WTPFEX6  Z9.2
    ......
 INPUT
    SEQN     1-5
    DMPFSEQ  6-10
    DMPSTAT  11
    ......
LABEL
    SEQN     = "Sample person identification number"
    DMPFSEQ  = "Family sequence number"
    DMPSTAT  = "Examination/interview Status"

Any idea how to read this into a friendly format?

Adam Waring
  • 1,158
  • 8
  • 20
  • Do you know how the data should look like? – Maël Nov 30 '21 at 12:18
  • I think it should be a table of data with ~30k rows and ~356 columns. Column names are present in the LABEL section of the second file. – Adam Waring Nov 30 '21 at 12:23
  • 1
    [Here](https://stackoverflow.com/questions/50298419/import-dat-file-from-repository-using-r)'s a similar question. – Maël Nov 30 '21 at 12:37
  • There are multiple packages to read in NHANES data: nhanes-A, RNHANES and others... unfortunately they cannot read this specific NHANES dataset, only the continuous NHANES from 1999 onwards. – Adam Waring Nov 30 '21 at 13:10
  • Yes thank you I did not find that similar question but it proposes the same solution – Adam Waring Nov 30 '21 at 13:14

1 Answers1

1

It should be possible using the SAScii package. It might take a couple of minutes though.

library(SAScii)
read.SAScii("https://wwwn.cdc.gov/nchs/data/nhanes3/1a/lab.dat", 
                      "https://wwwn.cdc.gov/nchs/data/nhanes3/1a/lab.sas", zipped = F)
Maël
  • 45,206
  • 3
  • 29
  • 67