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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
* Each cases has many scores, objective is to identify the highest 3 scores of each case.
* Posted by David Marso to comp.syst-soft.stat.spss  on 03/24/1998.


data list free / x1 to x10.
begin data.
13 54 23 54 25 12 52 3 51 23
15 41 23 15 42 31 23 12 15 12
51 43 51 36 12 53 6 12 53 12
63 51 23 51 73 51 35 12 35 35
end data.


** ASSUMES THE DATA ARE POSITIVE **.
** TO JUST GET THE MAXIMUMS ** .

VECTOR WHAT (3).
loop #=1 to 3.
COMPUTE WHAT(#)=MAX(X1 TO X10).

* A FLAG TO TRAP TIES *.
COMPUTE #FOUND=0.
DO REPEAT X=X1 to X10 .
DO IF X=WHAT(#) AND NOT #FOUND.
* A LITTLE TRICK TO GET THE CURRENT MAXIMUM OUT OF THE WAY *.
COMPUTE X=-X.
* SO WE DON'T KILL ANY TIES * .
COMPUTE #FOUND=1.
END IF.
END REPEAT.
END LOOP.
DO REPEAT X=X1 TO X10.
IF X < 0 X=-X.
END REPEAT.
FORMATS ALL (F2.0).
LIST.



** ANOTHER WAY ** .
data list free / x1 to x10.
begin data.
13 54 23 54 25 12 52 3 51 23
15 41 23 15 42 31 23 12 15 12
51 43 51 36 12 53 6 12 53 12
63 51 23 51 73 51 35 12 35 35
end data.

* ASSUMES RELEVANT DATA ARE CONTIGUOUS BUT NOT NECESSARILY POSITIVE*. 
VECTOR X=X1 TO X10 / #(10) / WHAT (3).
LOOP ##=1 TO 10.
+ COMPUTE #(##)=X(##).
END LOOP.

loop #=1 to 3.
+ COMPUTE WHAT(#)=MAX(X1 TO X10).
+ COMPUTE #FOUND=0.
+ LOOP ##= 1 to 10.
+ DO IF X(##)=WHAT(#).
+ COMPUTE X(##)=$SYSMIS.
+ COMPUTE #FOUND=1.
+ END IF.
+ END LOOP IF #FOUND.
END LOOP .
LOOP ##=1 TO 10.
+ COMPUTE X(##)=#(##).
END LOOP.
LIST.

** TO GET MAXIMUMS AND THEIR LOCATION ** .

VECTOR WHAT (3) / WHERE(3).
loop #=1 to 3.
COMPUTE WHAT(#)=MAX(X1 TO X10).
COMPUTE #FOUND=0.
DO REPEAT X=X1 to X10 / Ind = 1 TO 10.
DO IF X=WHAT(#) AND NOT #FOUND.
COMPUTE WHERE(#)=Ind.
COMPUTE X=-X.
COMPUTE #FOUND=1.
END IF.
END REPEAT.
END LOOP.

DO REPEAT X=X1 TO X10.
IF X < 0 X=-X.
END REPEAT.
FORMATS ALL (F2.0).
LIST.