Skip to contents

Reads a SAS transport file (.xpt) and integrates with mariposa's tagged NA system. Handles both native SAS special missing values and user-specified numeric missing codes (via tag_na). Transport files are a platform-independent SAS data format commonly used for FDA submissions and data exchange.

Usage

read_xpt(path, tag_na = NULL, verbose = FALSE)

Arguments

path

Path to a SAS transport file (.xpt).

tag_na

Numeric vector of values to treat as missing (e.g., c(-9, -8, -42)). These values will be converted to tagged NAs across all numeric variables. Default: NULL (only detect native SAS special missing values).

verbose

If TRUE, prints a message summarizing how many variables contain tagged missing values.

Value

A tibble with the SAS data. See read_sas() for details on tagged NA handling.

Details

SAS transport files support the same special missing values as .sas7bdat files (.A-.Z, ._). This format is self-contained and does not require a separate catalog file for value labels.

When tag_na is used, untag_na() can recover the original numeric codes.

Examples

# \donttest{
if (requireNamespace("haven", quietly = TRUE)) {
  # Roundtrip through a temporary .xpt transport file
  tmp <- tempfile(fileext = ".xpt")
  write_xpt(survey_data, tmp)
  data <- read_xpt(tmp)

  # Read with numeric missing codes tagged as distinct NA types
  data <- read_xpt(tmp, tag_na = c(-9, -8))

  unlink(tmp)
}
#>  Wrote 16 variables (2500 obs.) to file188e4acf9a81.xpt
# }