Add labels from proc_format file to SAS data file

add_proc_format_labels(
  df,
  proc_format,
  as_factor = FALSE,
  varname_case = c("lower", "upper"),
  debug_level = 0,
  ...
)

Arguments

df

Input data frame read from haven::read_sas

proc_format

Either path to SAS file with proc format statements or the results of read_proc_format.

as_factor

Convert labelled variables to factor with haven::as_factor?

varname_case

SAS variable names are not case-sensitive, but R variable names are. Choose one of "lower" or "upper" case to normalize the variable names in df and the varnames column of proc_format. Or set equal to NULL to leave both as-is.

debug_level

Default is 0. Level 1 prints confirmation of reading proc_format file. Level 2 prints confirmation that the labels were applied to each variable in df.

...

Arguments passed on to read_proc_format

file

Path to proc format file.

verbose

Writes out file path being read. May be removed in the future.

missing_values

Possible SAS values that should be treated as missing.

See also

Other SAS helper functions: read_proc_format(), read_sas_with_format()

Examples

if (FALSE) { bdat <- haven::read_sas("freepsa_data_feb16_d080516.sas7bdat") bdat2 <- add_proc_format_labels(bdat, "freepsa.sas_formats.feb16.d080516.sas") }