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
* This solution assumes your variables in col21 to 50 are numeric. If this is not the case, 
* you could autorecode the string variables.
* rlevesque@videotron.ca.

DATA LIST LIST /id(A2) var1(F8) var2(F8) var3(F8).
BEGIN DATA.
aa 1 1 9 
bb 2 2 4 
aa 3 6 9 
aa 4 7 8 
aa 4 7 2 
bb 4 8 3
END DATA.
LIST.

SORT CASES BY id.

* Number the records within each case.
DO IF $casenum=1.
COMPUTE recno=1.
ELSE.
COMPUTE recno=(lag(id)=id)*lag(recno)+1.
END IF.

* next line assumes you want a max of 3 records cancatenated.
SELECT IF (recno<4).

* in the rest of the syntax, replace 3 by the number of variables you have in col 21 to 50.
* and replace 9 by the product of 3 and the number of variables in col 21 to 50.
VECTOR v(9F8.0) /data1=var1 TO var3.
LOOP #cnt=1 TO 3.
COMPUTE v((recno-1)*3+#cnt)=data1(#cnt).
END LOOP.

AGGREGATE
  /OUTFILE=*
  /BREAK=id
  /v1 TO v9 = SUM(v1 TO v9).