Date: Thu, 2 Nov 2006 17:01:52 -0600
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Jim Moffitt <email@example.com>
Subject: Re: Looping Through Atypical Variable Names
Content-Type: text/plain; charset="iso-8859-2"
Thank you so much. The code did not run on my first attempt, but I placed a period at the end of the line that precedes the VALUE LABELS line and it ran beautifully. I really appreciate your help!
From: Jerabek Jindrich [mailto:JindraJerabek@seznam.cz]
Sent: Thursday, November 02, 2006 2:44 PM
To: Moffitt, James (West)
Subject: Re:Looping Through Atypical Variable Names
a macro could do.
Something like this (not tested!)
DEFINE !RE ().
!do !n = 1 !to 95
!LET !OldStart = !concat("q7.",!n,".1")
!LET !OldEnd = !concat("q7.",!n,".7")
!LET !NewStart = !concat("qbv7.",!n,".1") !LET !NewEnd = !concat("qbv7.",!n,".7") RECODE !OldStart TO !OldEnd (sysmis=1) (else=2) INTO !NewStart TO !NewEnd VALUE LABELS !NewStart TO !NewEnd 1 "Not Chosen" 2 "Chosen".
> ------------ Původní zpráva ------------
> Od: Jim Moffitt <firstname.lastname@example.org>
> Předmět: Looping Through Atypical Variable Names
> Datum: 02.11.2006 19:26:44
> I wrote the following syntax to recode some existing contiguous
> variables into some new variables.
> NUMERIC qbv7.1.1 TO qbv7.1.7 (f1.0)
> RECODE q7.1.1 TO q7.1.7 (sysmis=1) (else=2) INTO qbv7.1.1 TO qbv7.1.7.
> VALUE LABELS qbv7.1.1 TO qbv 7.1.7 1 "Not Chosen" 2 "Chosen".
> The code runs well, but I have to run it 95 times and I don't know how
> to create the loop that will address a different set of 7 contiguous
> variables every time the loop is run.
> Unfortunately, I have to loop through variable sets that are defined
> not by the first numerical character in the variable name, but by the
> So the first loop would create variables qbv7.1.1 TO qbv7.1.7 and
> recode variables q7.1.1 TO q7.1.7 into qbv7.1.1 TO qbv7.1.7.
> The next loop would create variables qbv7.2.1 TO qbv7.2.7 and recode
> variables q7.2.1 TO q7.2.7 into qbv7.2.1 TO qbv7.2.7.
> The next loop would create variables qbv7.3.1 TO qbv7.3.7 and recode
> variables q7.3.1 TO q7.3.7 into qbv7.3.1 TO qbv7.3.7.
> The final loop would create variables qbv7.95.1 TO qbv7.95.7 and
> recode variables q7.95.1 TO q7.95.7 into qbv7.95.1 TO qbv7.95.7.
> How would I write the code to loop through this process 95 times when
> its the second numeric character in the variable names that changes
> with each iteration?
> Thanks for the help.