haven (version 2.5.4)

read_sas: Read SAS files

Description

read_sas() supports both sas7bdat files and the accompanying sas7bcat files that SAS uses to record value labels.

Usage

read_sas(
  data_file,
  catalog_file = NULL,
  encoding = NULL,
  catalog_encoding = encoding,
  col_select = NULL,
  skip = 0L,
  n_max = Inf,
  cols_only = deprecated(),
  .name_repair = "unique"
)

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.

write_sas() returns the input data invisibly.

Arguments

data_file, catalog_file

Path to data and catalog files. The files are processed with readr::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.

col_select

One or more selection expressions, like in dplyr::select(). Use c() or list() to use more than one expression. See ?dplyr::select for details on available selection options. Only the specified columns will be read from data_file.

skip

Number of lines to skip before reading data.

n_max

Maximum number of lines to read.

cols_only

[Deprecated] cols_only is no longer supported; use col_select instead.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they are unique,

  • "universal": Make the names unique and syntactic

  • a function: apply custom name repair (e.g., .name_repair = make.names for names in the style of base R).

  • A purrr-style anonymous function, see rlang::as_function()

This argument is passed on as repair to vctrs::vec_as_names(). See there for more details on these terms and the strategies used to enforce them.

Examples

Run this code
path <- system.file("examples", "iris.sas7bdat", package = "haven")
read_sas(path)

Run the code above in your browser using DataCamp Workspace