若你希望第三行返回的第3大的值为 6,则有另外一种做法——寻找最大的值,然后将它写成缺失。重复3次,第3次的最大值即为要寻找的第3大的值。
- data test;
- input A B C D E F;
- cards;
- 5 6 4 10 8 9
- 8 6 6 5 9 4
- 8 6 6 9 9 4
- 9 9 9 9 9 9
- ;
- run;
- data want;
- set test;
- array _par_[6] A B C D E F;
- array _tmp_[6]_temporary_;
- array _max_[3]max1-max3;
- array _maxv_[3]$42. max1v max2v max3v;
- do i=1 to dim(_par_);
- _tmp_[i]=_par_[i];
- end;
- do t=1 to 3;
- _max_[t]=max(of _tmp_[*]);
- do i=1 to dim(_par_);
- if _tmp_[i]=_max_[t]^=. then do;
- _maxv_[t]=catx(',',_maxv_[t],vname(_par_[i]));
- _tmp_[i]=.;
- end;
- end;
- end;
- run;
复制代码