Dear SPPS user list,
I need a help regarding if-then rule.
I am trying to run the if-then rule in SPSS.
My interest is,
If Category equals to D, then, New_calc = Old_calc + 5
If Category equals to Z, then, New_calc = Old_calc + 5
If Category equals to K, then, New_calc = Old_calc +3
and so on...
The code I tried is below.
------------------------
NUMBER New_Calc(D2).
DO IF (Category EQ D).
COMPUTE New_Calc = 'Old_Calc+ 5'.
ELSE IF (Category EQ Z).
COMPUTE New_Calc = 'Old_Calc+ 5'.
ELSE IF (Category EQ K).
COMPUTE New_Calc = 'Old_Calc+3'.
ELSE IF (Category EQ X).
COMPUTE New_Calc = 'Old_Calc+3'.
ELSE IF (Category EQ U).
COMPUTE New_Calc = 'Old_Calc-4'.
ELSE
COMPUTE New_Calc = 'Old_Calc'.
END IF.
--------------------------------------------------------
It is showing the error and not running.
Thanks for your suggestion.
JAGANNATH
|
what is the data type of your category variable? If it is string, use "D" instead of D and so on. And why did u use ' with the numeric expression of Old_Cal+5 ? Old_Calc must be a number as you have defined New_Calc as number.
HTH. ----- Original Message ----- From: Jagannath Aryal To: [hidden email] Sent: 27 February, 2007 3:49 PM Subject: help Dear SPPS user list, I need a help regarding if-then rule. I am trying to run the if-then rule in SPSS. My interest is, If Category equals to D, then, New_calc = Old_calc + 5 If Category equals to Z, then, New_calc = Old_calc + 5 If Category equals to K, then, New_calc = Old_calc +3 and so on... The code I tried is below. ------------------------ NUMBER New_Calc(D2). DO IF (Category EQ D). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ Z). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ K). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ X). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ U). COMPUTE New_Calc = 'Old_Calc-4'. ELSE COMPUTE New_Calc = 'Old_Calc'. END IF. -------------------------------------------------------- It is showing the error and not running. Thanks for your suggestion. JAGANNATH ------------------------------------------------------------------------------ No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.23/700 - Release Date: 24-Feb-07 8:14 PM |
In reply to this post by Jagannath Aryal
Quote string values. Do not quote variable names or formulas/equations, as in:
do if Category = 'D'. compute New_Calc=Old_calc+5. Also, either drop the NUMBER command (it isn't really necessary) or use a valid format (which D2 is not), such as F2. ________________________________ From: SPSSX(r) Discussion on behalf of Jagannath Aryal Sent: Tue 2/27/2007 3:49 AM To: [hidden email] Subject: help Dear SPPS user list, I need a help regarding if-then rule. I am trying to run the if-then rule in SPSS. My interest is, If Category equals to D, then, New_calc = Old_calc + 5 If Category equals to Z, then, New_calc = Old_calc + 5 If Category equals to K, then, New_calc = Old_calc +3 and so on... The code I tried is below. ------------------------ NUMBER New_Calc(D2). DO IF (Category EQ D). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ Z). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ K). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ X). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ U). COMPUTE New_Calc = 'Old_Calc-4'. ELSE COMPUTE New_Calc = 'Old_Calc'. END IF. -------------------------------------------------------- It is showing the error and not running. Thanks for your suggestion. JAGANNATH |
In reply to this post by Jagannath Aryal
Also you need to put a period after the ELSE.
So you should have: ..... ELSE. COMPUTE New_Calc=Old_calc. END IF. Dominic Lusinchi Statistician Far West Research Statistical Consulting San Francisco, California 415-664-3032 www.farwestresearch.com -----Original Message----- From: Oliver, Richard [mailto:[hidden email]] Sent: Tuesday, February 27, 2007 4:36 AM Subject: Re: help Quote string values. Do not quote variable names or formulas/equations, as in: do if Category = 'D'. compute New_Calc=Old_calc+5. Also, either drop the NUMBER command (it isn't really necessary) or use a valid format (which D2 is not), such as F2. ________________________________ From: SPSSX(r) Discussion on behalf of Jagannath Aryal Sent: Tue 2/27/2007 3:49 AM To: [hidden email] Subject: help Dear SPPS user list, I need a help regarding if-then rule. I am trying to run the if-then rule in SPSS. My interest is, If Category equals to D, then, New_calc = Old_calc + 5 If Category equals to Z, then, New_calc = Old_calc + 5 If Category equals to K, then, New_calc = Old_calc +3 and so on... The code I tried is below. ------------------------ NUMBER New_Calc(D2). DO IF (Category EQ D). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ Z). COMPUTE New_Calc = 'Old_Calc+ 5'. ELSE IF (Category EQ K). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ X). COMPUTE New_Calc = 'Old_Calc+3'. ELSE IF (Category EQ U). COMPUTE New_Calc = 'Old_Calc-4'. ELSE COMPUTE New_Calc = 'Old_Calc'. END IF. -------------------------------------------------------- It is showing the error and not running. Thanks for your suggestion. JAGANNATH |
In reply to this post by Oliver, Richard
Still shorter would be to write:
if (Category = 'D') New_Calc=Old_calc+5. --- "Oliver, Richard" <[hidden email]> wrote: > Quote string values. Do not quote variable names or > formulas/equations, as in: > > do if Category = 'D'. > compute New_Calc=Old_calc+5. > > Also, either drop the NUMBER command (it isn't > really necessary) or use a valid format (which D2 is > not), such as F2. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Jagannath > Aryal > Sent: Tue 2/27/2007 3:49 AM > To: [hidden email] > Subject: help > > > Dear SPPS user list, > > > I need a help regarding if-then rule. > > > I am trying to run the if-then rule in SPSS. > > > My interest is, > > > If Category equals to D, then, New_calc = Old_calc + > 5 > If Category equals to Z, then, New_calc = Old_calc + > 5 > If Category equals to K, then, New_calc = Old_calc > +3 > and so on... > > > The code I tried is below. > ------------------------ > NUMBER New_Calc(D2). > DO IF (Category EQ D). > COMPUTE New_Calc = 'Old_Calc+ 5'. > ELSE IF (Category EQ Z). > COMPUTE New_Calc = 'Old_Calc+ 5'. > ELSE IF (Category EQ K). > COMPUTE New_Calc = 'Old_Calc+3'. > ELSE IF (Category EQ X). > COMPUTE New_Calc = 'Old_Calc+3'. > ELSE IF (Category EQ U). > COMPUTE New_Calc = 'Old_Calc-4'. > ELSE > COMPUTE New_Calc = 'Old_Calc'. > END IF. > > > > It is showing the error and not running. > > > Thanks for your suggestion. > > > JAGANNATH > Cheers! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ____________________________________________________________________________________ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 |
In the context of the original example, DO IF makes more sense than IF.
-----Original Message----- From: Albert-jan Roskam [mailto:[hidden email]] Sent: Wednesday, February 28, 2007 10:35 AM To: Oliver, Richard; [hidden email] Subject: Re: help Still shorter would be to write: if (Category = 'D') New_Calc=Old_calc+5. --- "Oliver, Richard" <[hidden email]> wrote: > Quote string values. Do not quote variable names or > formulas/equations, as in: > > do if Category = 'D'. > compute New_Calc=Old_calc+5. > > Also, either drop the NUMBER command (it isn't > really necessary) or use a valid format (which D2 is > not), such as F2. > > ________________________________ > > From: SPSSX(r) Discussion on behalf of Jagannath > Aryal > Sent: Tue 2/27/2007 3:49 AM > To: [hidden email] > Subject: help > > > Dear SPPS user list, > > > I need a help regarding if-then rule. > > > I am trying to run the if-then rule in SPSS. > > > My interest is, > > > If Category equals to D, then, New_calc = Old_calc + > 5 > If Category equals to Z, then, New_calc = Old_calc + > 5 > If Category equals to K, then, New_calc = Old_calc > +3 > and so on... > > > The code I tried is below. > ------------------------ > NUMBER New_Calc(D2). > DO IF (Category EQ D). > COMPUTE New_Calc = 'Old_Calc+ 5'. > ELSE IF (Category EQ Z). > COMPUTE New_Calc = 'Old_Calc+ 5'. > ELSE IF (Category EQ K). > COMPUTE New_Calc = 'Old_Calc+3'. > ELSE IF (Category EQ X). > COMPUTE New_Calc = 'Old_Calc+3'. > ELSE IF (Category EQ U). > COMPUTE New_Calc = 'Old_Calc-4'. > ELSE > COMPUTE New_Calc = 'Old_Calc'. > END IF. > > > > It is showing the error and not running. > > > Thanks for your suggestion. > > > JAGANNATH > Cheers! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ____________________________________________________________________________________ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 |
Just curious... what would be the difference between the two alternatives?
Oliver, Richard wrote: > In the context of the original example, DO IF makes more sense than IF. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Wednesday, February 28, 2007 10:35 AM > To: Oliver, Richard; [hidden email] > Subject: Re: help > > Still shorter would be to write: > if (Category = 'D') New_Calc=Old_calc+5. > > > > --- "Oliver, Richard" <[hidden email]> wrote: > > >> Quote string values. Do not quote variable names or >> formulas/equations, as in: >> >> do if Category = 'D'. >> compute New_Calc=Old_calc+5. >> >> -- Daniel Robertson Sr. Research and Planning Associate Institutional Research and Planning Cornell University 440 Day Hall, Ithaca NY 14853-2801 ph:607.255.9642 / irp.cornell.edu |
In reply to this post by Jagannath Aryal
'Do if' allows more than one conversion with the same condition. (if
this is true, then do the next N things) 'If' is for one conversion and is much simpler if there is only one change needed per condition. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Daniel Robertson Sent: Wednesday, February 28, 2007 10:59 AM To: [hidden email] Subject: Re: [SPSSX-L] help Just curious... what would be the difference between the two alternatives? Oliver, Richard wrote: > In the context of the original example, DO IF makes more sense than IF. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Wednesday, February 28, 2007 10:35 AM > To: Oliver, Richard; [hidden email] > Subject: Re: help > > Still shorter would be to write: > if (Category = 'D') New_Calc=Old_calc+5. > > > > --- "Oliver, Richard" <[hidden email]> wrote: > > >> Quote string values. Do not quote variable names or >> formulas/equations, as in: >> >> do if Category = 'D'. >> compute New_Calc=Old_calc+5. >> >> -- Daniel Robertson Sr. Research and Planning Associate Institutional Research and Planning Cornell University 440 Day Hall, Ithaca NY 14853-2801 ph:607.255.9642 / irp.cornell.edu PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
To me the most important thing with DO IF is the ability to use something other than a simple arithmetic assignment. For example you could stick a COUNT or RECODE command inside the block.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Melissa Ives Sent: Wednesday, February 28, 2007 11:06 AM To: [hidden email] Subject: Re: help 'Do if' allows more than one conversion with the same condition. (if this is true, then do the next N things) 'If' is for one conversion and is much simpler if there is only one change needed per condition. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Daniel Robertson Sent: Wednesday, February 28, 2007 10:59 AM To: [hidden email] Subject: Re: [SPSSX-L] help Just curious... what would be the difference between the two alternatives? Oliver, Richard wrote: > In the context of the original example, DO IF makes more sense than IF. > > -----Original Message----- > From: Albert-jan Roskam [mailto:[hidden email]] > Sent: Wednesday, February 28, 2007 10:35 AM > To: Oliver, Richard; [hidden email] > Subject: Re: help > > Still shorter would be to write: > if (Category = 'D') New_Calc=Old_calc+5. > > > > --- "Oliver, Richard" <[hidden email]> wrote: > > >> Quote string values. Do not quote variable names or >> formulas/equations, as in: >> >> do if Category = 'D'. >> compute New_Calc=Old_calc+5. >> >> -- Daniel Robertson Sr. Research and Planning Associate Institutional Research and Planning Cornell University 440 Day Hall, Ithaca NY 14853-2801 ph:607.255.9642 / irp.cornell.edu PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
Free forum by Nabble | Edit this page |