loop though

Discussions about editing and cleaning data
Forum rules
New release: CSPro 8.0
Post Reply
leulae
Posts: 46
Joined: December 16th, 2016, 5:51 am

loop though

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: loop though

Post 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
leulae
Posts: 46
Joined: December 16th, 2016, 5:51 am

Re: loop though

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: loop though

Post by josh »

No. That is not possible in CSPro.
leulae
Posts: 46
Joined: December 16th, 2016, 5:51 am

Re: loop though

Post 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.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: loop though

Post by josh »

Maybe if you tell us more generally what you trying to do we can come up with something.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: loop though

Post 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;
Post Reply