I'm looking for a syntax similar to that below (which does not work).
vector v(50). vector w(50). loop #item = 1 to 50. + compute w(#item) = v(#item). end loop. exe. (as a short form for: compute v1 = w1. compute v2 = w2. compute v3 = w3. (no python, that would be easy)
Dr. Frank Gaeth
|
Hi Frank,
I tested the syntax below and it worked smoothly for 3 variables. It should work for more than 3 variables.
vector r(3,f2). exe. vector v=v1 to v3 /r=r1 to r3. loop #i=1 to 3. comp r(#i)=v(#i). end loop. exe. vlad
On Wed, Dec 14, 2011 at 9:13 AM, drfg2008 <[hidden email]> wrote: I'm looking for a syntax similar to that below (which does not work). |
In reply to this post by drfg2008
is vector v populated?
What do you mean it does not work? What precedes the snippet you posted? this works on my system. new file. input program. vector x (3,f3). loop id = 1 to 5. loop #p = 1 to 3. compute x(#p) = rnd(rv.normal(50,10)). end loop. end case. end loop. end file. end input program. do repeat varx = x1 to x3/varv = v1 to v3. end repeat. compute varv=varx. vector w(3,f3). loop #item = 1 to 3. + compute w(#item) = v(#item). end loop. list. Art Kendall Social Research Consultants On 12/14/2011 12:13 PM, drfg2008 wrote: ===================== 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 REFCARDI'm looking for a syntax similar to that below (which does not work). vector v(50). vector w(50). loop #item = 1 to 50. + compute w(#item) = v(#item). end loop. exe. (as a short form for: compute v1 = w1. compute v2 = w2. compute v3 = w3. (no python, that would be easy) ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-tp5075099p5075099.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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
Art Kendall
Social Research Consultants |
Dear all,
I think the short notation ("vector v(30).") only works as long as no variables v1, v2, ... , v30 already exist. In order to copy 30 existing variables (v1-v30) as (w1-w30) you could use vector v=v1 to v30. vector w(30). loop #i = 1 to 30. compute w(#item) = v(#item). end loop. exe. or easier do repeat v=v1 to v30/w=w1 to w30. comp w=v. end repeat. exe. Date: Wed, 14 Dec 2011 14:24:52 -0500 From: [hidden email] Subject: Re: loop To: [hidden email] is vector v populated? What do you mean it does not work? What precedes the snippet you posted? this works on my system. new file. input program. vector x (3,f3). loop id = 1 to 5. loop #p = 1 to 3. compute x(#p) = rnd(rv.normal(50,10)). end loop. end case. end loop. end file. end input program. do repeat varx = x1 to x3/varv = v1 to v3. end repeat. compute varv=varx. vector w(3,f3). loop #item = 1 to 3. + compute w(#item) = v(#item). end loop. list. Art Kendall Social Research Consultants On 12/14/2011 12:13 PM, drfg2008 wrote: ===================== 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 REFCARDI'm looking for a syntax similar to that below (which does not work). vector v(50). vector w(50). loop #item = 1 to 50. + compute w(#item) = v(#item). end loop. exe. (as a short form for: compute v1 = w1. compute v2 = w2. compute v3 = w3. (no python, that would be easy) ----- Dr. Frank Gaeth FU-Berlin -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-tp5075099p5075099.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
Dear all,
thanks for your help! The shortest syntax seems to be do repeat v=v1 to v30/w=w1 to w30. comp w=v. end repeat. exe. It works (couldn't imagine to do a loop within one row)
Dr. Frank Gaeth
|
Administrator
|
Actually (not to be pedantic) if *ALL* you wish to achieve is copying a set of variables, the shortest syntax *IS* (probably also more efficient WRT computational resources)...
RECODE v1 TO v30 (ELSE=COPY) into w1 to w30. You will find with experience that LOOP.. END LOOP is in many ways, *much* more flexible than DO REPEAT.
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?" |
In reply to this post by drfg2008
This untested line may be shortest, Frank.
recode v1 to v50 (else=copy) into w1 to w50. Best. vlad
On Thu, Dec 15, 2011 at 12:08 AM, drfg2008 <[hidden email]> wrote: Dear all, |
Free forum by Nabble | Edit this page |