用IML过程最为快捷。这是我的程序段,用了你从1到5的观测,在程序里运行成功。将我的程序段稍加改动,就能得到你想要的结果,相信下面的步骤你能解决了。
data test;
input ID X;
cards;
1 4
2 6
3 2
4 5
5 2
;
run;
proc print data=test;
run;
proc IML;
use test;
read all var {ID X} into matrix;
print matrix;
n=nrow(matrix);
Pool=j(n,1,0);
R=j(n,1,0);
do i=1 to n;
Pool[i]=Matrix[i,2];
t=0;
do j=1 to n;
if Matrix[j,2] >= Pool[i] then t=t+1;
end;
R[i]=t;
end;
print Matrix R;
newone=matrix||R;
create newone var {ID X R};
append from newone;
quit;
proc print data=newone;
run;