1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
* execute a macro for each distinct value (or set of values) of a data file.
* Posted to SPSSX-L list by Raynald Levesque 2004/10/08.
* Website: www.spsstools.net

DATA LIST LIST /id    score1 .
BEGIN DATA
1 2
2 5
3 7
1 5
2 5
3 5
END DATA.
SAVE OUTFILE='c:\\temp\\data.sav'.

*//////////////////////.
DEFINE !macro (id=!TOKENS(1))
GET FILE='c:\\temp\\data.sav'.
SELECT IF id=!id.
GRAPH
  /BAR(SIMPLE)=COUNT BY score1.
!ENDDEFINE
*//////////////////////.

GET FILE='c:\\temp\\data.sav'.
AGGREGATE OUTFILE=*
	/BREAK=id
	/notused=N.
WRITE OUTFILE='c:\\temp\\syntax.sps' /'!macro id='id.
EXECUTE.

INCLUDE 'c:\\temp\\syntax.sps'.