/* ranksame (returns the vector of ranks of a vector including same numbers) */ new; cls; x={3,2,2,1,4,5,5}; print/rz x~ranksame(x); proc ranksame(x); local n,y,i,j,k,index; n=rows(x); y=zeros(n,1); i=1; do while i<=n; index=sumc(x.==minc(x)); k=0; j=0; do while j<=index-1; k=k+(i+j); j=j+1; endo; k=k/index; y=y+k*(x.==minc(x)); x=x+(x.==minc(x))*1e256; i=i+index; endo; retp(y); endp;