Test Run
library(SASxport)
## Loading required package: chron
## Loading required package: Hmisc
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
##
## Loaded SASxport version 1.5.0 (2014-07-21).
##
## Type `?SASxport' for usage information.
#####
## R version of the example given in TS-140
#####
## manually create a data set
abc <- data.frame( x=c(1, 2, NA, NA ), y=c('a', 'B', NA, '*' ) )
## look at it
abc
## x y
## 1 1 a
## 2 2 B
## 3 NA <NA>
## 4 NA *
## add a format specifier (not used by R)
SASformat(abc$x) <- 'date7.'
## add a variable label (not used by R)
label(abc$y) <- 'character variable'
## add a dataset label and type
label(abc) <- 'Simple example'
SAStype(abc) <- 'MYTYPE'
## verify the additions
str(abc)
## 'data.frame': 4 obs. of 2 variables:
## $ x: atomic 1 2 NA NA
## ..- attr(*, "SASformat")= chr "date7."
## $ y: Factor w/ 3 levels "*","a","B": 2 3 NA 1
## ..- attr(*, "label")= chr "character variable"
## - attr(*, "label")= chr "Simple example"
## - attr(*, "SAStype")= chr "MYTYPE"
# create a SAS XPORT file
write.xport( abc, file="xxx.xpt" )
# list the contents of the file
lookup.xport("xxx.xpt")
##
## SAS xport file
## --------------
## Filename: `xxx.xpt'
##
## Variables in data set `ABC':
## dataset name type format flength fdigits iformat iflength ifdigits
## ABC X numeric DATE 7 0 0 0
## ABC Y numeric RFMTA 0 0 0 0
## label nobs
## 4
## character variable 4
##
## Variables in data set `FORMATS':
## dataset name type format flength fdigits iformat iflength
## FORMATS FMTNAME character 0 0 0
## FORMATS START character 0 0 0
## FORMATS END character 0 0 0
## FORMATS LABEL character 0 0 0
## FORMATS MIN numeric 0 0 0
## FORMATS MAX numeric 0 0 0
## FORMATS DEFAULT numeric 0 0 0
## FORMATS LENGTH numeric 0 0 0
## FORMATS FUZZ numeric 0 0 0
## FORMATS PREFIX character 0 0 0
## FORMATS MULT numeric 0 0 0
## FORMATS FILL character 0 0 0
## FORMATS NOEDIT numeric 0 0 0
## FORMATS TYPE character 0 0 0
## FORMATS SEXCL character 0 0 0
## FORMATS EEXCL character 0 0 0
## FORMATS HLO character 0 0 0
## FORMATS DECSEP character 0 0 0
## FORMATS DIG3SEP character 0 0 0
## FORMATS DATATYPE character 0 0 0
## FORMATS LANGUAGE character 0 0 0
## ifdigits label nobs
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## 0 3
## reload the data
xxx.abc <- read.xport("xxx.xpt")
## and look at it
xxx.abc
## X Y
## 1 1960-01-02 a
## 2 1960-01-03 B
## 3 <NA> <NA>
## 4 <NA> *
## Check the label and type
label(xxx.abc)
## X Y
## "" "character variable"
SAStype(xxx.abc)
## [1] "MYTYPE"
## Note that the variable names and SAS dataset type have been converted
## to uppercase