read.sas
is a general function for reading sas7bdat files.
It supports a variety of complex sas7bdat files, x86 and x64, big and small
endian, and both compression types. It has been tested with numeric and
character data, and provides helper functions for converting sas7bdat to R
types Date
and POSIXct
. Time variables are converted to characters.
Conversion to date variables is applied if a known date, datetime or time
format is found in the sas7bdat file. For user-defined formats, the package
provides functions to convert from sas7bdat to R.
Input files may contain deleted rows that are marked as deleted instead of
being removed from the input data. These are removed on import, if you still
need them look at remove_deleted
. Formats, labels and additional file
information are available with attributes()
.
read.sas(
file,
debug = FALSE,
convert_dates = TRUE,
recode = TRUE,
select.rows = NULL,
select.cols = NULL,
remove_deleted = TRUE,
rownames = FALSE,
empty_to_na = FALSE
)
file to read
print debug information
default is TRUE
default is TRUE
integer. Vector of rows to import. Minimum 0. Rows
imported are sorted. If 0 is in select.rows
, zero rows are returned.
character: Vector of variables to select.
logical if deleted rows should be removed from data
first column will be used as rowname and removed from data
logical. In SAS empty characters are missing. this option
allows to convert ""
to NA_character_
when importing.
fl <- system.file("extdata", "cars.sas7bdat", package = "readsas")
read.sas(fl)
#> speed dist
#> 1 4 2
#> 2 4 10
#> 3 7 4
#> 4 7 22
#> 5 8 16
#> 6 9 10
#> 7 10 18
#> 8 10 26
#> 9 10 34
#> 10 11 17
#> 11 11 28
#> 12 12 14
#> 13 12 20
#> 14 12 24
#> 15 12 28
#> 16 13 26
#> 17 13 34
#> 18 13 34
#> 19 13 46
#> 20 14 26
#> 21 14 36
#> 22 14 60
#> 23 14 80
#> 24 15 20
#> 25 15 26
#> 26 15 54
#> 27 16 32
#> 28 16 40
#> 29 17 32
#> 30 17 40
#> 31 17 50
#> 32 18 42
#> 33 18 56
#> 34 18 76
#> 35 18 84
#> 36 19 36
#> 37 19 46
#> 38 19 68
#> 39 20 32
#> 40 20 48
#> 41 20 52
#> 42 20 56
#> 43 20 64
#> 44 22 66
#> 45 23 54
#> 46 24 70
#> 47 24 92
#> 48 24 93
#> 49 24 120
#> 50 25 85