LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2012)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 1 Apr 2012 14:55:57 -0400
Reply-To:   "Maguin, Eugene" <emaguin@buffalo.edu>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Maguin, Eugene" <emaguin@buffalo.edu>
Subject:   Re: Setting bits in SPSS variable
In-Reply-To:   <043c01cd1036$009fbf40$01df3dc0$@gmail.com>
Content-Type:   multipart/alternative;

Mike, There a couple of different ways of doing something like what you want. Assuming VarA-VarC has value 0,1. Using strings. String comb(a3). Compute comb=concat(string(vara,f1.0), string(varb,f1.0), string(varc,f1.0)).

Using numeric Compute comb=100*vara+10*varb+varc.

Gene Maguin

From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Mike Pritchard Sent: Sunday, April 01, 2012 2:34 PM To: SPSSX-L@LISTSERV.UGA.EDU 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.

Etc.

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.

COMPUTE Comb=$SYSMIS. 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. EXECUTE .

As usual with my questions, this feels like something that should be obvious.

Thanks in advance. Mike

_________________________________________________________________________ Mike Pritchard | mikep@5circles.com<mailto:mikep@5circles.com> | 5 Circles Research<http://www.5circles.com/> | 425-444-3410 (c) | 425-968-3883 (o) Research to help companies build products that people buy


[text/html]


Back to: Top of message | Previous page | Main SPSSX-L page