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 (August 2004)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 27 Aug 2004 10:35:28 -0500
Reply-To:   "Oliver, Richard" <richard@spss.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   "Oliver, Richard" <richard@spss.com>
Subject:   Re: Compute using multiple IFs
Comments:   To: John Dashper <John.Dashper@SELECTIVE.CO.UK>
Content-Type:   text/plain; charset="us-ascii"

Although I would also recommend DO IF/ELSE IF/END IF rather than a series of IF statements (even though the IF statements require fewer lines of code), I don't think it makes any difference in processing time as long as there are no intervening EXECUTE commands.

For example:

if (x=1) y=3. if (x=2) y=4. execute.

and

do if (x=1). compute y=3. else if (x=2). compute y=4. end if. execute.

will, I think, take the same amount of processing time, since in both cases the data file is only read once.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of John Dashper Sent: Friday, August 27, 2004 10:08 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Compute using multiple IFs

Much better with Do If.Only one pass of the file.

String special (A30).

do if(q7a_1>0). compute special = table1e. else if(q7b_1>0). compute special = table2e . else if(q7c_1>0). compute special = table3e .

etc

end if. exe.

OK?

John Dashper

> -----Original Message----- > From: Nico Peruzzi, Ph.D. [mailto:nperuzzi@yahoo.com] > Sent: 27 August 2004 16:08 > To: SPSSX-L@LISTSERV.UGA.EDU > Subject: Compute using multiple IFs > > Hi Listers, > > I am trying to compute a new variable (let's call it > "special") that does the following: > > -it equals the value in a variable called "table1e" if > variable "q7a_1" > 0 > -it equals the value in "table2e" if variable "q7b_1" > 0 > -equals value in table3e if q7c_1 >0 > etc. > > the q7 variable series variables are mutually exclusive, > and they occur in a specific order (i.e., q7a_1 would be > the first one to check for a value, then q7b, etc.) > > When I pasted out of the GUI, doing one if statement, I got > the following: > > IF (q7a_1>0) special = table1e . > EXECUTE . > > Would I just string a few of these statements together? > > IF (q7a_1>0) special = table1e . > IF (q7b_1>0) special = table2e . > IF (q7c_1>0) special = table3e . > etc > EXECUTE . > > Thanks in advance for any tips, > > Nico


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