Search code examples
syntaxspss

How can I use SPSS syntax to mask all values except for 2 specified values in a variable?


I'm trying to manipulate some SPSS data and the code I'm using is specific to masking all values in a variable and replacing it with "MASKED" but I'd like to keep 2 specified values unmasked while masking the rest with the word "MASKED". The variable I am working with is v1 and the values I want to retain are "N/A" and "Did not answer".

The code I'm using:

ALTER TYPE v1 (A15).
RECODE v1 ("" = "") (else = "MASKED"). 

Solution

  • You should alter your code like this:

    RECODE v1 ("" "N/A" "Did not answer" = copy) (else = "MASKED").