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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
* Code by Raynald Levesque.

DATA LIST fixed records = 1/1 seg 1-2 (f) state 3-4 (f)
ori 5-13 (a) inum 14-25 (a) idate 26-33 (f) offcode 34-36 (a) a_c 37 (a) susp1 38 (a) susp2 39 (a) susp3 40 (a)
loc 41-42 (f) enter 43-44 (f) method 45 (a) tyact1 46 (a) tyact2 47 (a) tyact3 48 (a)
weap1 49-51 (a) weap2 53-54 (a) weap3 55-57 (a) bias 58-59 (f). 

BEGIN DATA.
0133ori_ori__inum_inum___10311999of1astu1234mtuvwea wewea22
0133ori_ori__inum_inum___11311999of2bstu1234mtuvwea wewea22
0133ori_ori__inum_inum___12151999of3cstu1234mtuvwea wewea22
0133ori_ori__inum_inum___12291999of4dstu1234mtuvwea wewea22
0133ori2ori__inum_inum___10311999of5estu1234mtuvwea wewea22
0133ori2ori__inum_inum___11011999of6fstu1234mtuvwea wewea22
END DATA.
LIST. 

*Calulate the unique id.
STRING id(A23).
COMPUTE id=CONCAT(STRING(seg,F2),STRING(state,F2),ori,inum).
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 concatenated.
SELECT IF (recno<4). 

* The only reason to define the numeric variables is to create them side by side, this 
allows the use of the TO keyword in the aggregate command.
* you will have to add the missing variables. 
NUMERIC idate1 TO idate3.
STRING offcode1 TO offcode3(A3) a_c1 TO a_c3(A1).
DO IF recno=1.
COMPUTE idate_1=idate.
COMPUTE offcode1=offcode.
COMPUTE a_c1=a_c. 

* you have to add the missing variables.
ELSE IF recno=2.
COMPUTE idate_2=idate.
COMPUTE offcode2=offcode.
COMPUTE a_c2=a_c. 

* you have to add the missing variables.
ELSE.
COMPUTE idate_3=idate.
COMPUTE offcode3=offcode.
COMPUTE a_c3=a_c. 
* you have to add the missing variables.
END IF. 

* you have to add the missing variables at the end of the AGG command.. 
AGGREGATE
/OUTFILE=*
/BREAK=id
/ idate_1 TO idate_3=MAX(idate_1 TO idate_3) 
/offcode1 TO offcode3=MAX(offcode1 TO offcode3)
/a_c1 TO a_c3=MAX(a_c1 TO a_c3).