Page 1 of 1

loop though

Posted: February 1st, 2018, 1:48 am
by leulae
Dear All,

It would be grateful, if anyone suggests me a method to loop though variables as we did in SPSS

Sample Code:(SPSS)
DO REPEAT V= V1 TO V4 / W = W1 TO W4 / X = X1 TO X4 / Y = Y1 TO Y4.
COMPUTE X = V + W.
COMPUTE Y = V - W.
END REPEAT.
Leulae

Re: loop though

Posted: February 1st, 2018, 7:02 am
by josh
I don't know SPSS but that looks like what would be a do loop with a subscript. See the help under "subscripts". The second example uses a loop:

http://www.csprousers.org/help/CSPro/subscripts.html

Re: loop though

Posted: February 1st, 2018, 9:05 am
by leulae
Thanks Josh for your reply,

This is not kind of Roster or array processing (Looping with same variable eg. age(i) )

If we have Data file with variable name age, sex, maritalstatus,…..,nationality as near columns, in SPSS we can loop from age to nationality, I am seeking same in Cspro


Thanks

Leulae
josh wrote:I don't know SPSS but that looks like what would be a do loop with a subscript. See the help under "subscripts". The second example uses a loop:

http://www.csprousers.org/help/CSPro/subscripts.html

Re: loop though

Posted: February 1st, 2018, 9:27 am
by josh
No. That is not possible in CSPro.

Re: loop though

Posted: February 1st, 2018, 9:32 am
by leulae
Thank you Josh,

Need to process all items (variables) from one place beginning to end, any hint?

Leulae
josh wrote:No. That is not possible in CSPro.

Re: loop though

Posted: February 1st, 2018, 9:35 am
by josh
Maybe if you tell us more generally what you trying to do we can come up with something.

Re: loop though

Posted: February 26th, 2018, 2:23 pm
by Gregory Martin
This isn't the cleanest code, but you can use getvalue/setvalue. For example:
do numeric ctr = 1 while ctr <= 4

    setvalue(maketext("X%d",ctr),getvalue(maketext("V%d",ctr) + getvalue(maketext("W%d",ctr));
    setvalue(maketext("Y%d",ctr),getvalue(maketext("V%d",ctr) - getvalue(maketext("W%d",ctr));

enddo;