Reading supports both sas7bdat files and the accompanying sas7bdat files that SAS uses to record value labels. Writing value labels is not currently supported.

read_sas(data_file, catalog_file = NULL, encoding = NULL,
  catalog_encoding = encoding, cols_only = NULL)

write_sas(data, path)

Arguments

data_file, catalog_file

Path to data and catalog files. The files are processed with datasource().

encoding, catalog_encoding

The character encoding used for the `data_file` and `catalog_encoding` respectively. A value of `NULL` uses the encoding specified in the file; use this argument to override it if it is incorrect.

cols_only

A character vector giving an experimental way to read in only specified columns.

data

Data frame to write.

path

Path to file where the data will be written.

Value

A tibble, data frame variant with nice defaults.

Variable labels are stored in the "label" attribute of each variable. It is not printed on the console, but the RStudio viewer will show it.

Examples

path <- system.file("examples", "iris.sas7bdat", package = "haven") read_sas(path)
#> # A tibble: 150 x 5 #> Sepal_Length Sepal_Width Petal_Length Petal_Width Species #> <dbl> <dbl> <dbl> <dbl> <chr> #> 1 5.10 3.50 1.40 0.200 setosa #> 2 4.90 3.00 1.40 0.200 setosa #> 3 4.70 3.20 1.30 0.200 setosa #> 4 4.60 3.10 1.50 0.200 setosa #> 5 5.00 3.60 1.40 0.200 setosa #> 6 5.40 3.90 1.70 0.400 setosa #> 7 4.60 3.40 1.40 0.300 setosa #> 8 5.00 3.40 1.50 0.200 setosa #> 9 4.40 2.90 1.40 0.200 setosa #> 10 4.90 3.10 1.50 0.100 setosa #> # ... with 140 more rows