How to write to .csv so that "NA" missing values are read by SPSS as missing not as string

Viewed 578

I need to know how to read a .csv file with a lot of missing values created in R into SPSS such that those missing values are read as missing (. in SPSS) not as a string reading NA.

There are a lot of variables each with a lot of entries, and most of those entries are NA, so I don't have time to go through all the variables recoding each one-by-one from "NA" into "SYSMISS".

Does anyone have any ideas

I have tried

write.csv(df, "file.csv", na = ".") 

but SPSS just reads this as a string, not as a missing value.

1 Answers

Instead of writing the file differently, you can leave as is. After reading the file into SPSS, with the problematic variables turned into strings with NA values, use:

alter type var1 to var250 (f8.2).

This will change these variables back into numbers, turning all the NA values into missing values. (Note 1: use to only for groups of consecutive variables, e.g var1 to var12 var14 var18 var20 to var30. Note 2: replace f8.2 with the number format you need)

Related