SAScii test: Import .dat files for SAS using .sas scripts from R

## Settings for RMarkdown http://yihui.name/knitr/options#chunk_options
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, tidy = FALSE, 
    echo = T, fig.width = 10, fig.height = 10)
options(width = 116, scipen = 5, digits = 5)

setwd("~/statistics/Rmedstats/")

Update 2012-10-25: Author's message

SAScii's author, Anthony Damico gave me additional information!

awesome that you're using the sascii package :)
for nhanes, try my fully-commented scripts in https://github.com/ajdamico/usgsd
i will post a full blog on nhanes in two weeks at http://usgsd.blogspot.com/

NHANES II data

The National Health and Nutrition Examination Survey (NHANES) is a series of national survey conducted in the US, and is a rich source of variety of information. NHANES I and II data files are in .dat format with .sas script for import.

NHANES I: http://www.cdc.gov/nchs/nhanes/nhanesi.htm
NHANES II: http://www.cdc.gov/nchs/nhanes/nhanesii.htm

Import (This will take a while)

## Load SAScii
library(SAScii)

## Import using read.SAScii     # It takes time.
nhanesii.allergy <-
    read.SAScii(fn = "ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/nhanes/nhanesii/DU5309.txt",
                sas_ri = "ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/nhanes/nhanesii/DU5309_F.sas")

Show contents

Only the values are imported. No labeling by converting to factors.

head(nhanesii.allergy)
  SEQN N2AL0006 N2AL0010 N2AL0011 N2AL0012 N2AL0013 N2AL0024 N2AL0025 N2AL0026 N2AL0027 N2AL0028 N2AL0029 N2AL0030
1   37     5371       NA        2        2       NA        1        1        9        9        9       NA        6
2   38     5371       NA        2        2       NA        1        1        9        9        9       NA        9
3   44     5371       NA        2        1       NA        1        1        9        9        9       NA        6
4   45     5371       NA        2        2       NA        1        1        9        9        9       NA        3
5   48     5371       NA        2        2       NA        1        1        9        9        9       NA        3
6   49     5371       NA        2        2       NA        1        1        9        9        9       NA        6
  N2AL0032 N2AL0034 N2AL0035 N2AL0036 N2AL0037 N2AL0042 N2AL0047 N2AL0049 N2AL0051 N2AL0053 N2AL0055 N2AL0056
1        2       NA        4        1      103       NA        6       NA        2       70        1        1
2        3       NA        5        1      302       NA       11       NA       10       64        1        1
3        1       NA        4        1       46       NA        8       NA        1       68        2        3
4        1       NA        4        1      231       NA       11       NA        9       64        1        1
5        2       NA        4        1      241       NA       10       NA        7       65        2        2
6        2       NA        4        1      254       NA        9       NA       11       66        1        2
  N2AL0057 N2AL0059 N2AL0060 N2AL0062 N2AL0064 N2AL0065 N2AL0066 N2AL0067 N2AL0068 N2AL0069 N2AL0070 N2AL0071
1       12        1        8        0       NA       NA       NA       NA       NA       NA       NA       NA
2       12        1        9       25        2       NA       NA       NA       NA       NA       NA       NA
3       12        1        7       22        2       NA       NA       NA       NA       NA       NA       NA
4       95        1       13       26        2       NA       NA       NA       NA       NA       NA       NA
5       13        1       10       25        2       NA       NA       NA       NA       NA       NA       NA
6       12        1       10       24        2       NA       NA       NA       NA       NA       NA       NA
  N2AL0072 N2AL0073 N2AL0076 N2AL0079 N2AL0080 N2AL0081 N2AL0082 N2AL0091 N2AL0092 N2AL0093 N2AL0094 N2AL0095
1       NA       NA       NA       NA       NA       NA       NA        8        4       NA        1       NA
2       NA       NA       NA       NA       NA       NA       NA        9        5       NA        1       NA
3       NA       NA       NA       NA       NA       NA       NA        4        2       NA        1       NA
4       NA       NA       NA       NA       NA       NA       NA        3        1       NA        1       NA
5       NA       NA       NA       NA       NA       NA       NA        3        1       NA        1       NA
6       NA       NA       NA       NA       NA       NA       NA        4        2       NA        1       NA
  N2AL0096 N2AL0097 N2AL0098 N2AL0099 N2AL0100 N2AL0101 N2AL0103 N2AL0104 N2AL0105 N2AL0106 N2AL0107 N2AL0109
1       NA       NA       NA       NA        2       12        2        2        2        9       21       NA
2       NA       NA       NA       NA        2       16        1        2        2        9       18       NA
3       NA       NA       NA       NA        2       18        1        0        1        5       16     5500
4       NA       NA       NA       NA        2       19        1        0        1        7       18       NA
5       NA       NA       NA       NA        2       19        3        0        2        9       12        0
6       NA       NA       NA       NA        2       11        3        0        2        9       15     2000
  N2AL0113 N2AL0114 N2AL0115 N2AL0119 N2AL0120 N2AL0121 N2AL0125 N2AL0126 N2AL0127 N2AL0131 N2AL0132 N2AL0133
1       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
2       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
3        2       NA       NA        2       NA       NA        2       NA       NA        2       NA       NA
4       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
5        2       NA       NA        1       NA     1728        2       NA       NA        2       NA       NA
6        2       NA       NA        1       NA     2664        2       NA       NA        2       NA       NA
  N2AL0137 N2AL0138 N2AL0139 N2AL0143 N2AL0144 N2AL0145 N2AL0149 N2AL0150 N2AL0151 N2AL0155 N2AL0156 N2AL0157
1       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
2       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
3        2       NA       NA        2       NA       NA        2       NA       NA        2       NA       NA
4       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA       NA
5        2       NA       NA        2       NA       NA        2       NA       NA        2       NA       NA
6        2       NA       NA        2       NA       NA        2       NA       NA        2       NA       NA
  N2AL0161 N2AL0162 N2AL0163 N2AL0167 N2AL0168 N2AL0169 N2AL0173 N2AL0177 N2AL0178 N2AL0179 N2AL0180 N2AL0181
1       NA       NA       NA       NA       NA       NA       NA        2        2       NA       NA       NA
2       NA       NA       NA       NA       NA       NA       NA        2        2       NA       NA       NA
3        2       NA       NA        2       NA       NA     5500        2        1        1       NA       NA
4       NA       NA       NA       NA       NA       NA       NA        2        2       NA       NA       NA
5        1       NA       40        2       NA       NA     1768        2        1        1       NA       NA
6        2       NA       NA        2       NA       NA     4664        2        1        1       NA       NA
  N2AL0182 N2AL0183 N2AL0184 N2AL0186 N2AL0188 N2AL0190 N2AL0192 N2AL0206 N2AL0207 N2AL0208 N2AL0209 N2AL0210
1       NA       NA        2       25       76        6       NA        1        2        1        3      290
2       NA       NA        2       24       76       11       NA        1        2        1        3       91
3       NA       NA        2       20       76        8       NA        6        2        1        3       71
4       NA       NA        3       11       76       11       NA        1        2        1        3      193
5       NA       NA        2       25       76       10       NA        5        2        1        3       40
6       NA       NA        2       28       76        9       NA        2        2        1        3       61
  N2AL0213 N2AL0247 N2AL0249 N2AL0251 N2AL0253 N2AL0255 N2AL0256 N2AL0257 N2AL0259 N2AL0260 N2AL0262 N2AL0264
1       NA       44       NA        8       31        1        1       12        2        8       44        1
2       NA       63       NA        6       12        2        1       13        3        9       33        2
3       NA       37       NA        3       38        1        3       72        2        7       21        1
4       NA       37       NA        8       38        2        1       95        4        9       28        1
5       NA       32       NA        7       43        2        2       13        4       10       28        1
6       NA       28       NA        4       47        2        2       13        4       10       31        2
  N2AL0265 N2AL0266 N2AL0267 N2AL0268 N2AL0269 N2AL0270 N2AL0271 N2AL0272 N2AL0273 N2AL0276 N2AL0279 N2AL0280
1        1       NA       NA        1        1       NA       NA       NA      717      233        1        1
2        1       NA       NA        1        1       NA       NA       NA      857      230        4        2
3        1       NA       NA        1        1       NA       NA       NA      278      715        1        2
4        1       NA       NA        1        1       NA       NA       NA      707      394        1        2
5        2       NA        2       NA       NA        2        2       NA       NA       NA       NA        2
6        2       NA        1        2        1       NA       NA       NA      769      984        1        2
  N2AL0281 N2AL0282 N2AL0288 N2AL0294 N2AL0300 N2AL0306 N2AL0312 N2AL0318 N2AL0324 N2AL0326 N2AL0327 N2AL0328
1        2    21910    18948        0    22813        0        0       NA        1        1        1       NA
2       NA     8210     7345        0        0    17097        0       NA        1        1        2       NA
3       NA     7169     6478        0        0    14543        0       NA        1        1        2       NA
4       NA     8210     7345        0    16210        0        0       NA        1        1        2       NA
5       NA     8271     7511        0        0    12701        0       NA        1        1        2       NA
6       NA    10429     9216        0    22220        0        0       NA        1        1        2       NA
  N2AL0401 N2AL0405 N2AL0406 N2AL0409 N2AL0411 N2AL0412 N2AL0414 N2AL0416 N2AL0418 N2AL0419 N2AL0421 N2AL0423
1     5309        0       NA        2        3       NA        0        0        2        0        0       10
2     5309        0       NA        9        3       NA        0        0        2        0        0       10
3     5309        1       NA       88        3       NA       88       88        8       88       88       88
4     5309        0       NA        9        3       NA        0        0        2        0        0       10
5     5309        0       NA        7        3       NA        0        0        2        0        0       10
6     5309        0       NA        7        3       NA        0        0        2        0        0       10
  N2AL0425 N2AL0427 N2AL0429 N2AL0431 N2AL0432 N2AL0434 N2AL0436 N2AL0438 N2AL0440 N2AL0442 N2AL0444 N2AL0445
1       10        0        0        2        0        0       20       10        0        0        2        0
2       10        0        0        2        0        0       20       10        0        0        2        0
3       88       88       88        8       88       88       88       88       88       88        8       88
4       10        0        0        2        0        0       20       19        0        0        2        0
5       10        0        0        2        0        0       20       10        0        0        2        0
6       10        0        0        2        0        0       20       10        0        0        2        0
  N2AL0447 N2AL0449 N2AL0451 N2AL0453 N2AL0455 N2AL0457 N2AL0458 N2AL0460 N2AL0462 N2AL0464 N2AL0466 N2AL0468
1        0       10       10        0        0        2        0        0       20       10        0        0
2        0       10       10        0        0        2        0        0       20       10        0        0
3       88       88       88       88       88        8       88       88       88       88       88       88
4        0       10       10        0        0        2        0        0       20       19        0        0
5        0       10       10        0        0        2        0        0       20       10        0        0
6        0       10       10        0        0        2        0        0       20       10        0        0
  N2AL0470 N2AL0471 N2AL0473 N2AL0475 N2AL0477 N2AL0479 N2AL0481 N2AL0483 N2AL0484 N2AL0486 N2AL0488 N2AL0490
1        2        0        0       10       10        0        0        2        0        0       20       10
2        2        0        0       10       10        0        0        2        0        0       20       10
3        8       88       88       88       88       88       88        8       88       88       88       88
4        2        0        0       10       10        0        0        2        0        0       20       19
5        2        0        0       10       10        0        0        2        0        0       20       10
6        2        0        0       10       10        0        0        2        0        0       20       10
  N2AL0492 N2AL0494 N2AL0496 N2AL0497 N2AL0499 N2AL0501 N2AL0503 N2AL0505 N2AL0507 N2AL0509 N2AL0510 N2AL0512
1        0        0        2        0        0       10       10        0        0        2        0        0
2        0        0        2        0        0       10       10        0        0        2        0        0
3       88       88        8       88       88       88       88       88       88        8       88       88
4        0        0        2        0        0       10       10        0        0        2        0        0
5        0        0        2        0        0       10       10        0        0        2        0        0
6        0        0        2        0        0       10       10        0        0        2        0        0
  N2AL0514 N2AL0516 N2AL0518 N2AL0520 N2AL0522 N2AL0523 N2AL0525 N2AL0527 N2AL0529 N2AL0531 N2AL0533 N2AL0535
1       20       10        0        0        2        0        0       10       10        0        0        2
2       20       10        0        0        2        0        0       10       10        0        0        2
3       88       88       88       88        8       88       88       88       88       88       88        8
4       20       19        0        0        2        0        0       10       10        0        0        2
5       20       10        0        0        2        0        0       10       10        0        0        2
6       20       10        0        0        2        0        0       10       10        0        0        2
  N2AL0536 N2AL0538 N2AL0540 N2AL0542 N2AL0544 N2AL0546 N2AL0548 N2AL0549 N2AL0551 N2AL0553 N2AL0555 N2AL0557
1        0        0       20       10        0        0        2        0        0       10       10        0
2        0        0       20       10        0        0        2        0        0       10       10        0
3       88       88       88       88       88       88        8       88       88       88       88       88
4        0        0       20       19        0        0        2        0        0       10       10        0
5        0        0       20       10        0        0        2        0        0       10       10        0
6        0        0       20       10        0        0        2        0        0       10       10        0
  N2AL0559 N2AL0561 N2AL0562 N2AL0564 N2AL0566 N2AL0568 N2AL0570 N2AL0572 N2AL0574 N2AL0575 N2AL0577 N2AL0579
1        0        2        0        0       20       10        0        0        2        0        0       10
2        0        2        0        0       20       10        0        0        2        0        0       10
3       88        8       88       88       88       88       88       88        8       88       88       88
4        0        2        0        0       20       19        0        0        2        0        0       10
5        0        2        0        0       20       10        0        0        2        0        0       10
6        0        2        0        0       20       10        0        0        2        0        0       10
  N2AL0581 N2AL0583 N2AL0585 N2AL0587 N2AL0588 N2AL0590 N2AL0592 N2AL0594 N2AL0596 N2AL0598 N2AL0600 N2AL0601
1       10        0        0        2        0        0       20       10        0        0        2        0
2       10        0        0        2        0        0       20       10        0        0        2        0
3       88       88       88        8       88       88       88       88       88       88        8       88
4       10        0        0        2        0        0       20       19        0        0        2        0
5       10        0        0        2        0        0       20       10        0        0        2        0
6       10        0        0        2        0        0       20       10        0        0        2        0
  N2AL0603 N2AL0605 N2AL0607 N2AL0609 N2AL0611 N2AL0613 N2AL0614 N2AL0616 N2AL0618 N2AL0620 N2AL0622 N2AL0624
1        0       10       10        0        0        2        0        0       20       10        0        0
2        0       10       10        0        0        2        0        0       20       10        0        0
3       88       88       88       88       88        8       88       88       88       88       88       88
4        0       10       10        0        0        2        0        0       20       19        0        0
5        0       10       10        0        0        2        0        0       20       10        0        0
6        0       10       10        0        0        2        0        0       20       10        0        0
  N2AL0626 N2AL0627 N2AL0629 N2AL0631 N2AL0633 N2AL0635 N2AL0637 N2AL0639 N2AL0640 N2AL0642 N2AL0644 N2AL0646
1        2        0        0       10       10        0        0        2        0        0       20       10
2        2        0        0       10       10        0        0        2        0        0       20       10
3        8       88       88       88       88       88       88        8       88       88       88       88
4        2        0        0       10       10        0        0        2        0        0       20       10
5        2        0        0       10       10        0        0        2        0        0       20       10
6        2        0        0       10       10        0        0        2        0        0       20       10
  N2AL0648 N2AL0650 N2AL0652 N2AL0653 N2AL0655 N2AL0657 N2AL0659 N2AL0661 N2AL0663 N2AL0665 N2AL0666 N2AL0668
1        0        0        2        0        0       10       10        0        0        2        0        0
2       88       88        8       12       12       10       11       88       88        8       12       12
3       88       88        8       88       88       88       88       88       88        8       88       88
4       88       88        8       88       88       88       16       88       88        8       88       88
5        0        0        2        0        0       10       10        0        0        2        0        0
6        0        0        2        0        0       10       10        0        0        2        0        0
  N2AL0670 N2AL0672 N2AL0674 N2AL0675 N2AL0676 N2AL0677 N2AL0678 N2AL0679 N2AL0680 N2AL0681 N2AL0682 N2AL0683
1       20       10       NA        0        0        0        0        0        0        0        0        0
2       20       11       NA        0        0        0        0        0        0        0        0        0
3       88       88       NA        0        0        0        0        0        0        0        0        0
4       88       16       NA        0        0        0        0        0        0        0        0        0
5       20       10       NA        0        0        0        0        0        0        0        0        0
6       20       10       NA        0        0        0        0        0        0        0        0        0
  N2AL0684 N2AL0685 N2AL0686 N2AL0687 N2AL0688 N2AL0689 N2AL0690 N2AL0691 N2AL0692 N2AL0693 N2AL0694 N2AL0695
1        0        0        0        0        0        0        0        0        0        0        0       NA
2        0        0        0        0        0        0        0        0        0        0        0       NA
3        0        0        0        0        0        0        0        0        0        0        0       NA
4        0        0        0        0        0        0        0        0        0        0        0       NA
5        0        0        0        0        0        0        0        0        0        0        0       NA
6        0        0        0        0        0        0        0        0        0        0        0       NA