Skip to contents

[Stable]

SAS imports missing data as empty strings or strings with whitespaces only. This helper function can be used to convert these values to NAs.

Usage

sas_na(x, empty = TRUE, whitespaces = TRUE)

Arguments

x

factor or character vector

empty

boolean if true empty strings get replaced by NA

whitespaces

boolean, if true then strings made from whitespaces only get replaced with NA

Examples

sas_na(c("1", "", " ", "   ", "b"))
#> [1] "1" NA  NA  NA  "b"
sas_na(factor(c("", " ", "b")))
#> [1] <NA> <NA> b   
#> Levels: b

is.na(sas_na(c("1", "", " ", "   ", "b")))
#> [1] FALSE  TRUE  TRUE  TRUE FALSE