Problems looping in SPSS19

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems looping in SPSS19

Alexa
Hi everyone, I am having problems looping in SPSS 19.
I am trying to identify particular string values in a series of variables
and it is not working:
The following are my commands:

DO REPEAT a = ICD9X_CODE1_somb.1 TO ICD9X_CODE1_somb.3818.
COMPUTE HL_dx = 0.
IF (a = '3890') | (a = '3891') | (a = '3892') | (a = '389') | (a = '3897')
| (a = '3898') | (a = '3899') HL_dx = 1.
END REPEAT.
EXECUTE.

I receive no error messages, however, all values of HL_dx are being
returned as 0 when I know that there are values of '389' '3890'... in the
data.

Any suggestions?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Problems looping in SPSS19

Rick Oliver-3
Move the COMPUTE statement out of the DO REPEAT loop, and put it before the DO REPEAT loop.





From:        Alexa <[hidden email]>
To:        [hidden email]
Date:        09/21/2011 05:56 PM
Subject:        Problems looping in SPSS19
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi everyone, I am having problems looping in SPSS 19.
I am trying to identify particular string values in a series of variables
and it is not working:
The following are my commands:

DO REPEAT a = ICD9X_CODE1_somb.1 TO ICD9X_CODE1_somb.3818.
COMPUTE HL_dx = 0.
IF (a = '3890') | (a = '3891') | (a = '3892') | (a = '389') | (a = '3897')
| (a = '3898') | (a = '3899') HL_dx = 1.
END REPEAT.
EXECUTE.

I receive no error messages, however, all values of HL_dx are being
returned as 0 when I know that there are values of '389' '3890'... in the
data.

Any suggestions?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Problems looping in SPSS19

David Marso
Administrator
In reply to this post by Alexa
Alexa,
As Rick stated below, move the COMPUTE HL_dx *BEFORE* the DO REPEAT
(Otherwise only ICD9X_CODE1_somb.3818 gets flagged).
OTOH, the following is *MUCH* more efficient.  Also guarding against leading spaces.
COMPUTE HL_dx = 0.
VECTOR a=ICD9X_CODE1_somb.1 TO ICD9X_CODE1_somb.3818.
 /* assuming you have 3818 variables in the mix */.
LOOP #=1 TO 3818.
+  IF ANY(LTRIM(a(#)), '3890','3891','3892','389', '3897','3898','3899') HL_dx = 1.
END LOOP IF  HL_dx = 1.
HTH, David
---
Alexa wrote
Hi everyone, I am having problems looping in SPSS 19.
I am trying to identify particular string values in a series of variables
and it is not working:
The following are my commands:

DO REPEAT a = ICD9X_CODE1_somb.1 TO ICD9X_CODE1_somb.3818.
COMPUTE HL_dx = 0.
IF (a = '3890') | (a = '3891') | (a = '3892') | (a = '389') | (a = '3897')
| (a = '3898') | (a = '3899') HL_dx = 1.
END REPEAT.
EXECUTE.

I receive no error messages, however, all values of HL_dx are being
returned as 0 when I know that there are values of '389' '3890'... in the
data.

Any suggestions?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Problems looping in SPSS19

Alexa
In reply to this post by Alexa
Thanks!

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD