Please help! REPEAT question

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

Please help! REPEAT question

Rob360
Dear all,
I'm new to the SPSS syntax, but have some MATLAB experience.
Very stuck with the following:

I'd like to create 1440 new variables: bin0001 to bin1440
each variable will take the value '1' depending on whether its number is between the variables 'STRTTIME' and 'ENDTIME', which are already in the dataset.

I've come this far (example for bin 1343, which works!), but you've guessed it, I am not planning to type in the same code 1440 times....

DATASET ACTIVATE DataSet1.
IF  (1343 > STRTTIME & 1343 <= ENDTIME) bin1343=1.
EXECUTE.

Can somebody help me?
Thanks in advance,

Rob
Reply | Threaded
Open this post in threaded view
|

Re: Please help! REPEAT question

Bruce Weaver
Administrator
Is this what you have in mind?

NUMERIC bin0001 to bin1440 (f1.0).
VECTOR bin = bin0001 to bin1440.
LOOP # = 1 to 1440.
COMPUTE bin(#) = (# > STRTTIME & # <= ENDTIME).
END LOOP.
EXECUTE.


Rob360 wrote
Dear all,
I'm new to the SPSS syntax, but have some MATLAB experience.
Very stuck with the following:

I'd like to create 1440 new variables: bin0001 to bin1440
each variable will take the value '1' depending on whether its number is between the variables 'STRTTIME' and 'ENDTIME', which are already in the dataset.

I've come this far (example for bin 1343, which works!), but you've guessed it, I am not planning to type in the same code 1440 times....

DATASET ACTIVATE DataSet1.
IF  (1343 > STRTTIME & 1343 <= ENDTIME) bin1343=1.
EXECUTE.

Can somebody help me?
Thanks in advance,

Rob
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Please help! REPEAT question

Rob360
AWESOME Bruce.
That's it!!!

The SPSS help in the software (at least about the topics of loops and repeats) is very confusing to me.
Perhaps something worth improving now IBM is in control.

Thanks for your help.

Rob
Reply | Threaded
Open this post in threaded view
|

Re: Please help! REPEAT question

David Marso
Administrator
In reply to this post by Bruce Weaver
MUCH more efficient would be to set only the relevant (in range) bins ;-)

NUMERIC bin0001 to bin1440 (f1.0).
RECODE bin0001 to bin1440 (ELSE=0).
VECTOR bin = bin0001 to bin1440.
LOOP # = STRTTIME  to ENDTIME.
+  COMPUTE bin(#) = 1.
END LOOP.
* Also lose the EXECUTE *.  
* EXECUTE.
Bruce Weaver wrote
Is this what you have in mind?

NUMERIC bin0001 to bin1440 (f1.0).
VECTOR bin = bin0001 to bin1440.
LOOP # = 1 to 1440.
COMPUTE bin(#) = (# > STRTTIME & # <= ENDTIME).
END LOOP.
EXECUTE.


Rob360 wrote
Dear all,
I'm new to the SPSS syntax, but have some MATLAB experience.
Very stuck with the following:

I'd like to create 1440 new variables: bin0001 to bin1440
each variable will take the value '1' depending on whether its number is between the variables 'STRTTIME' and 'ENDTIME', which are already in the dataset.

I've come this far (example for bin 1343, which works!), but you've guessed it, I am not planning to type in the same code 1440 times....

DATASET ACTIVATE DataSet1.
IF  (1343 > STRTTIME & 1343 <= ENDTIME) bin1343=1.
EXECUTE.

Can somebody help me?
Thanks in advance,

Rob
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?"