Reads only the columns you ask for from the large fixed-width .dat file, using the
positions in its SAS program (nhanes3_layout()). Choose the columns by name with
vars, or, in an interactive session, leave vars out to pick them from a list (use
pattern to shorten the list first). SEQN, the respondent ID used to link files and
mortality, is always included when the file has it.
Usage
nhanes3_read(
file,
vars = NULL,
pattern = NULL,
recode = NULL,
id = "SEQN",
dat_file = NULL,
sas_file = NULL,
n_max = Inf
)Arguments
- file
A file name from
nhanes3_files(), or the path to a.sasprogram (then givedat_filetoo).- vars
Character vector of variable names to read. If
NULLin an interactive session, you choose from a list; otherwise an error asks you to supply them.- pattern
Optional regular expression that narrows the interactive list (name or label), as in
nhanes3_layout().- recode
Names of numeric variables (among
vars) whose all-8s and all-9s codes becomeNA. Default none.- id
Name of the ID column to always include, or
NULLfor none.- dat_file
Path to the
.datfile, if you already have it; otherwise the cached copy is used, downloaded on first use (about 195 MB for the exam file).- sas_file
Path to the
.sasprogram, if you already have it.- n_max
Maximum number of rows to read (default all), useful for a quick look.
Value
A tibble with the requested columns (numeric, except any $ character columns). It
carries attr(, "width"), the width of each field, and attr(, "var_labels"), the SAS
labels.
Details
NHANES III stores "blank but applicable" as all 8s and "don't know" as all 9s, sized to
the field (8/9 for a one-character item, 88888/99999 for a five-character
measurement). Left in place they look like real values. recode turns these into NA for
the variables you name. It is not applied to everything: IDs, weights and age have no such
codes, and many items have special codes of their own (666 for "varies", 777 for "less than
1 per day"), so check the codebook (nhanes3_download() with what = "codebook") first.
See also
nhanes3_layout(), nhanes3_files(), nhanes_mortality_parse() for the
NHANES III linked mortality file.