Date: Sun, 1 Apr 2012 14:55:57 -0400
Reply-To: "Maguin, Eugene" <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Maguin, Eugene" <firstname.lastname@example.org>
Subject: Re: Setting bits in SPSS variable
There a couple of different ways of doing something like what you want. Assuming VarA-VarC has value 0,1.
Compute comb=concat(string(vara,f1.0), string(varb,f1.0), string(varc,f1.0)).
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Mike Pritchard
Sent: Sunday, April 01, 2012 2:34 PM
Subject: Setting bits in SPSS variable
Is there an easy way to set bits in a an SPSS variable? I'm trying to create a variable based on the combinations of other (dichotomous) variables. The way that seems logically easy to me is to set a bit for each of the variables, and then the output variable will automatically represent the correct combination. Thus (pseudo code)
IF (VarA) COMPUTE Comb = Comb AND 1.
IF (VarB) COMPUTE Comb = Comb AND 2.
IF (VarC) COMPUTE Comb = Comb AND 4.
But I can't figure out how to do this. Instead, I'm using all the combinations with individual IF statements which works for a small number, but isn't very scalable and is easy to make mistakes.
IF ((VarA=1) AND (VarB=1) AND (VarC=1)) Comb=7.
IF ((VarA=1) AND (VarB=1) AND (VarC=0)) Comb=6.
IF ((VarA=1) AND (VarB=0) AND (VarC=1)) Comb=5.
IF ((VarA=1) AND (VarB=0) AND (VarC=0)) Comb=4.
IF ((VarA=0) AND (VarB=1) AND (VarC=1)) Comb=3.
IF ((VarA=0) AND (VarB=1) AND (VarC=0)) Comb=2.
IF ((VarA=0) AND (VarB=0) AND (VarC=1)) Comb=1.
IF ((VarA=0) AND (VarB=0) AND (VarC=0)) Comb=0.
As usual with my questions, this feels like something that should be obvious.
Thanks in advance.
Mike Pritchard | email@example.com<mailto:firstname.lastname@example.org> | 5 Circles Research<http://www.5circles.com/> | 425-444-3410 (c) | 425-968-3883 (o)
Research to help companies build products that people buy