Method for recoding all user-defined missing values from SPSS to NA during import in R?

49 Views Asked by At

I am using the haven package to import a large SPSS dataset into R. The dataset contains many variables with unique user-defined missing values--sometimes several for a single variable.

The date/time variables share 8888-08-08 and 9999-09-09 as user-defined missing values (signifying "Not Applicable" and "Unknown", respectively). Another set of variables related to ICD-10 codes contains 77777, 88888, and 99999 as missing values, indicating "Injured but Unknown Code", "Not Applicable", and "Unknown". Yet another set of variables contains the codes 66, 77, 88, and 99 (for "Not Applicable", "Refused to Answer", "Variable Did Not Exist at Time of Collection", and "Unknown")... etc.

My question is whether there is an argument in haven (or another data loading package in R) that will automatically convert these various user-defined missing values to NA during the import process of the original SPSS file.

I have tried the following without success:

df <- read_sav("/path/to/file.sav", user_na = FALSE)
0

There are 0 best solutions below