Skip to contents

Import SAS data into R

Usage

import_sas(
  sas_data,
  sas_formats_data,
  formats,
  bool_levels = c("yes", "no"),
  bool_true = "yes",
  bool_false = "no",
  formats_func = NULL,
  keep_unformatted = NULL
)

Arguments

sas_data

SAS survey data file

sas_formats_data

SAS formats data file (produced with CNTLOUT option of PROC FORMAT)

formats

how are formats specified?

bool_levels

variables that have these levels should be converted from factor (categorical) to logical

bool_true

level(s) of these variables that should be set to TRUE

bool_false

level(s) of these variables that should be set to FALSE

formats_func

only needed if formats = "funcname"

keep_unformatted

vector of variable names. Create unformatted versions of these variables.

The argument formats determines how formats are specified:

  • "attr": in attr(*, "format.sas")

  • "name": same as the variable name

  • "funcname": formats_func("x") is a function that returns the format name for variable "x"

Levels in bool_levels that are neither in bool_true or bool_false are set to NA.

Value

data.frame. If this is a complex survey, use svydesign to create a survey design object.

Examples

if (FALSE) {
d1 = import_sas(sas_data, sas_formats_data)
}