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,
  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

The character encoding used for the file. This defaults to the encoding specified in the file, or UTF-8. You can use this argument to override the value stored in the file if it is correct

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 × 5 #> Sepal_Length Sepal_Width Petal_Length Petal_Width Species #> <dbl> <dbl> <dbl> <dbl> <chr> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5.0 3.4 1.5 0.2 setosa #> 9 4.4 2.9 1.4 0.2 setosa #> 10 4.9 3.1 1.5 0.1 setosa #> # ... with 140 more rows