Date: Tue, 15 Aug 2006 21:22:10 -0400
Reply-To: Raynald Levesque <rlevesque@videotron.ca>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <rlevesque@videotron.ca>
Subject: Re: Need help with aggregate macro with multiple file saves
In-Reply-To: <200608151507.k7FEsll5021675@mailgw.cc.uga.edu>
Content-type: text/plain; charset=us-ascii
Hi
This is one way (of course "cleaner" solutions are possible using Python):
*////////////////////////////.
DEFINE !agg1 (gp = !ENCLOSE('[',']') / filen= !ENCLOSE('[',']')) .
!LET !cnt1=!BLANKS(0)
!DO !I !IN (!gp)
!LET !cnt1=!CONCAT(!cnt1,!BLANKS(1))
!LET !cnt2=!BLANKS(0)
!DO !name !IN (!filen)
!LET !cnt2=!CONCAT(!cnt2,!BLANKS(1))
!IF (!cnt2 = !cnt1) !THEN
!LET !filename=!name
!BREAK
!IFEND
!DOEND
GET FILE='C:\Program Files\SPSS\AML survival.sav'.
AGGREGATE
/OUTFILE=!QUOTE(!CONCAT ('C:\temp\', !filename, '.sav'))
/BREAK=!I
/time_mean = MEAN(time).
!DOEND
*////////////////////////////.
!ENDDEFINE .
SET MPRINT=YES.
!agg1 gp = [status chemo] filen = [a01 a02] .
This is the expanded syntax produced by the macro:
202 0 M> GET FILE='C:\Program Files\SPSS\AML survival.sav'.
203 0 M> AGGREGATE /OUTFILE= 'C:\temp\a01.sav' /BREAK= status /time_mean =
MEAN(time).
204 0 M>
205 0 M>
206 0 M> GET FILE='C:\Program Files\SPSS\AML survival.sav'.
207 0 M> AGGREGATE /OUTFILE= 'C:\temp\a02.sav' /BREAK= chemo /time_mean =
MEAN(time).
Cheers!
Raynald Levesque Raynald@spsstools.net
Visit my SPSS site: http://www.spsstools.net
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Ken
Chui
Sent: August 15, 2006 11:07 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Need help with aggregate macro with multiple file saves
Hello all,
I am trying to modify the following macro so that it would aggregate by
different break variables (status, chemo) and save a file separately. Right
now I can only use this version to come up with "status.sav" and
"chemo.sav"... how can I incorporate the second token !FILEN so that the
output file will be named "a01.sav" for 'status' and "a02.sav" for 'chemo'
separately? Thanks for any advice/help.
-Ken
DEFINE AGG1 (GP = !ENCLOSE('[',']') / FILEN = !ENCLOSE('[',']')) .
!DO !I !IN (!GP)
GET
FILE='C:\Program Files\SPSS\AML survival.sav'.
AGGREGATE
/OUTFILE=!QUOTE(!CONCAT ('C:\temp\', !I, '.sav'))
/BREAK=!I
/time_mean = MEAN(time).
!DOEND .
!ENDDEFINE .
AGG1 GP = [status chemo] FILEN = [a01 a02] .