Date: Thu, 22 Apr 2004 09:55:23 +0200
Reply-To: Spousta Jan <JSpousta@CSAS.CZ>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Spousta Jan <JSpousta@CSAS.CZ>
Subject: Re: loop in macros
Content-Type: text/plain; charset="iso-8859-2"
Dear Richard,
I agree with you, that Raynalds solution is rather complicated. But I think that we can simplify it even without new functions in macros (although I would be _very_ pleased if the macro language would have new features, e.g. standard arithmetics).
The simpler and less tricky solution for parallel processing of two (or more) lists in the SPSS macros should use functions !tail and !head. For example:
get file='c:\program files\spss\employee data.sav'.
define newsort (!pos = !cha ('/') / !pos = !cmd).
!let !adad = !2.
!let !command = 'SORT CASES BY '.
!do !column !in (!1).
!let !he = !head(!adad).
!let !adad = !tail(!adad).
!let !command = !concat(!command,!column," (",!he,") ").
!doend.
echo !quote(!command) .
!command .
!enddefine.
newsort gender jobcat salary / a d a .
Greetings
Jan
-----Original Message-----
From: Richard Ristow [mailto:wrristow@mindspring.com]
Sent: Wednesday, April 21, 2004 10:41 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: loop in macros
Raynald Levesque's code for this is a tremendous job, but my reaction
is, OUCH! What a set of tricks to get around SPSS limitations! The
goal, of course, is parallel processing of the lists in the two
arguments, as DO REPEAT/END REPEAT does with multiple variable or value
lists; and this is a fairly common need. This really needs a
macro-language extension. One possibility is extending !DO...!IN to do
parallel list processing like DO REPEAT: something like (this is *NOT*
currently valid macro code),
!DO !i !IN (!var1) /!j !IN (!sort)
<macro statements>
!DOEND
where this !var1 and !var2 lists are processed in parallel. Or an
explicit way of indexing the Nth element from a list, so *that* doesn't
need an inner !DO loop -- something like
!LET !j = !WORDOF(!SORT,n)
where 'n' is a macro expression evaluating to an integer. As frequently
stated, integer arithmetic in the macro language would make a BIG
difference, though that isn't crucial for this application; the existing
!DO !n = 1 to !FINISH
would work, if there were some way to find the stopping value -- say,
!LET !FINISH = !NWORDS(!SORT)
Raynald's work-around is wonderful, but I'd say it's a worse indictment
of the macro language than any polemic could be.