Search code examples
spss

Logical conditions with missing values


I'm using Transform > Compute Variable to OR two variables (B,C) together. My two vars can have values 1, 2, or 3. I want to calculate a third var that's 1 if either B or C is 1 and zero otherwise. This works

A = (B=1) | (C=1)

But I'm running into trouble if B or C is missing. What I'd like is

if B and C exist and B or C equals 1, A = 1
if B and C exist and neither equals 1, A = 0
if B is missing and C is missing, A = missing
if B or C is 1 and the other value is missing, A = 1
if B or C is not 1 and the other value is missing, A = 0

Can I use Transform > Compute Variable to accomplish this or do I need another approach?


Solution

  • Here's a one liner for this:

    compute A=max((B=1), (C=1)).
    exe.
    

    You can do this through the transformation menus, but I recommend getting used to (the power of) using syntax.