LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2006)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 2 Nov 2006 21:44:00 +0100
Reply-To:     =?us-ascii?Q?Jerabek=20Jindrich?= <JindraJerabek@seznam.cz>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         =?us-ascii?Q?Jerabek=20Jindrich?= <JindraJerabek@seznam.cz>
Subject:      =?us-ascii?Q?Re=3ALooping=20Through=20Atypical=20Variable=20Names?=
Comments: To: james.moffitt@thomson.com
In-Reply-To:  <945D579F76FD5741A043511E6FE99B570C74C3F5@TLRUSMNEAGMBX32.ERF.THOMSON.COM>
Content-Type: text/plain; charset="iso-8859-2"

Hello Jim,

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". !doend !ENDDEFINE.

!RE.

HTH Jindra

> ------------ Původní zpráva ------------ > Od: Jim Moffitt <james.moffitt@thomson.com> > 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". > EXECUTE. > > 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 > second. > > 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. > > >


Back to: Top of message | Previous page | Main SPSSX-L page