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
* Find 5 largest values within each case.
* Given by David Nichols on SPSSL-X list on 2000/3/29.

set mxloops=100.

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.

matrix.
get x /variables=x1 to x10.
compute out=make(nrow(x),5,0).
loop i=1 to 5.
compute out(:,i)=rmax(x).
loop j=1 to nrow(x).
loop k=1 to ncol(x).
do if x(j,k)=out(j,i).
compute x(j,k)=-1E+100.
break.
end if.
end loop.
end loop.
end loop.
save out /outfile=tmp.sav.
end matrix.