loop though

Discussions about editing and cleaning data
leulae
Posts: 36
Joined: December 16th, 2016, 5:51 am

loop though

Postby leulae » February 1st, 2018, 1:48 am

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

Re: loop though

Postby josh » February 1st, 2018, 7:02 am

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: 36
Joined: December 16th, 2016, 5:51 am

Re: loop though

Postby leulae » February 1st, 2018, 9:05 am

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

Re: loop though

Postby josh » February 1st, 2018, 9:27 am

No. That is not possible in CSPro.

leulae
Posts: 36
Joined: December 16th, 2016, 5:51 am

Re: loop though

Postby leulae » February 1st, 2018, 9:32 am

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

Re: loop though

Postby josh » February 1st, 2018, 9:35 am

Maybe if you tell us more generally what you trying to do we can come up with something.

Gregory Martin
Posts: 1038
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: loop though

Postby Gregory Martin » February 26th, 2018, 2:23 pm

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;


Return to “Editing”