How to replace identical values in multiple cases with the values of another variable? (SPSS)

Viewed 29

If my variable REF has the value NA in a certain line (case), I want it to be the value of CASE instead of NA.

My data set:

CASE REF
 1    NA
 2    NA
 3    1
 4    NA
 5    2
 6    1
 7    1
 8    4

Desired output:

CASE REF
 1    1
 2    2
 3    1
 4    4
 5    2
 6    1
 7    1
 8    4

I tried "Recode into Same Variables", but somehow I don't know how to reference the variable CASE in there. What is the correct way to use SPSS for this?

1 Answers

I am assuming ref is a numeric variable and when you say NA you mean missing values. If this is not the case, let me know in a comment and I will revise solution accordingly.

Assuming CASE is a variable in your dataset, this should do it:

if missing(ref) ref=case.

If by "CASE" you are referring to the case number and not a variable in the dataset, use this instead:

if missing(ref) ref=$casenum.
Related