LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (May 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 15 May 2007 23:38:56 -0400
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: Paired compute looping help
Comments: To: rwwalker@optonline.net
In-Reply-To:  <e31ecc921248d.464a70d1@optonline.net>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 10:47 PM 5/15/2007, Bob Walker wrote:

[test data omitted; see cited posting]

>Here's one approach: > >DEFINE !BUBBA() >!LET !MIN=1 !LET !MAX=5 >VECTOR V=!CONCAT("V",!MIN) TO !CONCAT("V",!MAX). > >!DO !A=!MIN !TO !MAX !DO !B=!A !TO !MAX >!IF (!A<>!B) !THEN >COMPUTE !CONCAT("V_",!A,!B)=V(!A)+V(!B). >!IFEND !DOEND !DOEND >EXECUTE. >DATASET NAME BUBBA WINDOW=FRONT. > >!ENDDEFINE.

Now, that is a SWEET little piece of macro writing.

Curious: since you're unrolling the COMPUTEs in a macro loop anyway, why not generate the arguments to the COMPUTEs by catenation, rather than vector indexing? Like this (WRR-not saved separately):

[test data]

DEFINE !BUBBA() !LET !MIN=1 !LET !MAX=5

!DO !A=!MIN !TO !MAX !DO !B=!A !TO !MAX !IF (!A<>!B) !THEN COMPUTE !CONCAT("V_",!A,!B)=!CONCAT("V",!A) + !CONCAT("V",!B). !IFEND !DOEND !DOEND !ENDDEFINE.

PRESERVE. SET MPRINT ON. !BUBBA. 144 M> 145 M> . 146 M> COMPUTE V_12 = V1 + V2. 147 M> COMPUTE V_13 = V1 + V3. 148 M> COMPUTE V_14 = V1 + V4. 149 M> COMPUTE V_15 = V1 + V5. 150 M> COMPUTE V_23 = V2 + V3. 151 M> COMPUTE V_24 = V2 + V4. 152 M> COMPUTE V_25 = V2 + V5. 153 M> COMPUTE V_34 = V3 + V4. 154 M> COMPUTE V_35 = V3 + V5. 155 M> COMPUTE V_45 = V4 + V5. 156 M> . RESTORE. 157 M> RESTORE.

DATASET NAME BUBBA WINDOW=FRONT.

LIST. [data listing]


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