SASxport: Read and Write 'SAS' 'XPORT' Files

> library(SASxport)

Attaching package: 'SASxport'
The following objects are masked from 'package:foreign':

    lookup.xport, read.xport
> data("Alfalfa")

バージョン: 1.5.2


関数名 概略
Alfalfa Example SAS data set
SASformat Set or Retreive the 'label', 'SASformat', 'SASiformat', or 'SAStype' attribute of a vector or (components of) a data frame
SASxport-package Read and Write SAS Export Files
lookup.xport Describe the Contents of an SAS XPORT File
makeSASNames Create valid and unique SAS names from a character vector.
read.xport Import a SAS XPORT File
toSAS.default Convert R Data Object for Storage in a SAS XPORT File
write.xport Write Data to a SAS XPORT File

Alfalfa

> data("Alfalfa")
> Alfalfa %>% {
+   class(.) %>% print()
+   dplyr::glimpse(.)
+ }
[1] "data.frame"
Observations: 40
Variables: 6
$ POP    (fctr) min, min, min, min, min, MAX, MAX, MAX, MAX, MAX, min,...
$ SAMPLE (int) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8...
$ REP    (int) 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2...
$ SEEDWT (int) 64, 54, 40, 45, 64, 75, 45, 63, 65, 59, 59, 46, 42, 38,...
$ HARV1  (dbl) 171.7, 138.2, 145.6, 170.4, 124.8, 179.0, 166.3, 169.7,...
$ HARV2  (dbl) 180.3, 150.7, 129.1, 191.2, 172.6, 235.3, 173.9, 155.8,...

lookup.xport

> alfFile <- system.file("extdata", "Alfalfa.xpt", package = "SASxport")
> lookup.xport(alfFile)

SAS xport file
--------------
Filename: `/Library/Frameworks/R.framework/Versions/3.2/Resources/library/SASxport/extdata/Alfalfa.xpt'

Variables in data set `SPEC':
 dataset   name      type format flength fdigits iformat iflength ifdigits
    SPEC    POP character              0       0                0        0
    SPEC SAMPLE   numeric              0       0                0        0
    SPEC    REP   numeric              0       0                0        0
    SPEC SEEDWT   numeric              0       0                0        0
    SPEC  HARV1   numeric              0       0                0        0
    SPEC  HARV2   numeric              0       0                0        0
 label nobs
         40
         40
         40
         40
         40
         40
> testFile <- system.file("extdata", "test2.xpt", package = "SASxport")
> w <- lookup.xport(testFile)
> w$Z$name
[1] "X3" "X4" "X5" "X6" "X7" "X8"

makeSASNames

Arguments

  • names
  • nchar
  • maxPasses
  • quiet
> c("height","weight","age","gender") %>% makeSASNames()
[1] "HEIGHT" "WEIGHT" "AGE"    "GENDER"

toSAS

Arguments

  • x
  • format
  • format.info
> ISOdate(2007, 08, 01, 10, 14, 37) %>% {
+   dateTimeObj <<- .
+   class(.) %>% print()
+   print(.)
+ }
[1] "POSIXct" "POSIXt" 
[1] "2007-08-01 10:14:37 GMT"
> toSAS(dateTimeObj)
[1] 1501614877
attr(,"tzone")
[1] "GMT"
attr(,"SASformat")
[1] "DATETIME16."