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
33
34
35
36
37
38
39
40
41
42
43
* The end of the !DO loop is a variable which was computed from the data file.
* rlevesque@videotron.ca.

SET MPRINT=no.

DATA LIST LIST /id(F8) var1(F8).
BEGIN DATA.
1 1
1 3
1 2
2 20
2 25
3 15
3 25
END DATA.
LIST.

SAVE OUTFILE='c:\\temp\\data.sav'.

COMPUTE break_v=(id=1).
AGGREGATE
 /OUTFILE=*
 /BREAK=break_v
 /var1_1 = SUM(var1).

DO IF break_v=1.
WRITE OUTFILE 'c:\\temp\\temp.sps' /"DEFINE !sum_1()"/var1_1/"!ENDDEFINE.".
END IF.
EXE.

INCLUDE 'c:\\temp\\temp.sps'.
GET FILE='c:\\temp\\data.sav'.

DEFINE !doit(nb_loop=!TOKENS(1))
!DO !cnt=1 !TO !nb_loop
COMPUTE !CONCAT(var,!cnt)=!cnt.
!DOEND
!ENDDEFINE

SET MPRINT=yes
!doit nb_loop=!sum_1.
SET MPRINT=no
EXECUTE.