Description Usage Arguments Details Value Note Author(s) References See Also Examples
This function writes one or more data frames into a SAS XPORT format library file.
1 2 3 4 5 6 7 8 9 10 |
... |
One or more data frames to be stored |
list |
A list containing data frames to be stored. |
file |
File name or connection object. Use "" to view the raw data |
verbose |
Logical flag controlling whether status is reported during processing |
sasVer |
SAS version string |
osType |
Operating system, defaults to "R X.Y.Z" for appropriate values of X, Y, and Z |
cDate |
Date object specifying dataset creation date |
formats |
Optional data frame containing SAS format information. |
autogen.formats |
Logical indicating whether SAS formats should be auto-generated for factor variables. |
The function creates a SAS XPORT data file (see reference) from one or more data frames. This file format imposes a number of constraints:
Data set and variable names are truncated to 8 characters and converted to upper case. All characters outside of the set A-Z, 0-9, and '\_' are converted to '\_'.
Character variables are stored as characters.
If autogen.formats=TRUE (the default), factor variables
are stored as numeric with an appropriate SAS format
specification. If autogen.formats=FALSE, factor variables
are stored as characters.
All numeric variables are stored as double-precision floating point values utilizing the IBM mainframe double precision floating point format (see the reference).
Date and time variables are either converted to number of days since 1960-01-01 (date only), or number of seconds since 1960-01-01:00:00:00 GMT (date-time variables).
Missing values are converted to the standard SAS missing value '.'
The SAS XPORT format allows each dataset to have a label and a type
(set via the label and SAStype functions).
In addition, each variable may have a corresponding label, display
format, and input format. To set these values, add the attribute
'label', 'SASformat', or 'SASiformat' to individual data frame. These
attributes may be set using the label,
SASformat, and SASiformat functions. (See
examples provided below.)
The actual translation of R objects to objects appropriate for SAS is
handled by the toSAS generic and associated methods,
which can be (re)defined by the user to provide fine-grained control.
No return value
This package was created with partial funding by Metrum Institute http://metruminstitute.org.
Gregory R. Warnes greg@warnes.net
SAS Technical Support document TS-140: “The Record Layout of a Data Set in SAS Transport (XPORT) Format” available at https://support.sas.com/techsup/technote/ts140.pdf
toSAS,
lookup.xport,
read.xport,
label,
SAStype,
SASformat,
and SASiformat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #####
## 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, '*'),
stringsAsFactors=TRUE
)
## look at it
abc
## 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)
# create a SAS XPORT file
tmp <- tempfile(fileext = ".dat")
write.xport( abc, file = tmp )
# list the contents of the file
lookup.xport(tmp)
## reload the data
xxx.abc <- read.xport(tmp)
## and look at it
xxx.abc
## Check the label and type
label(xxx.abc)
SAStype(xxx.abc)
## Note that the variable names and SAS dataset type have been converted
## to uppercase
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.