Here is a different approach using formats: data fmts; set two end=done; by descending rank; array a[3] Q_RATING R_RATING S_RATING; do i=1 to dim(a); start=a; if missing(start) then continue; fmtname=cats(scan(vname(a), 1, '_'), 'rank'); label=put(rank, best. -l); type='i'; output; end; if done then do fmtname='Qrank', 'Rrank', 'Srank'; hlo='o'; label=''; output; end; hlo=''; fmtname='rank2pct'; start=put(rank, best. -l); label=r_pct; type='n'; output; if done then do; hlo='o'; label=''; output; end; run; proc sort data=fmts; by fmtname start; run; proc format cntlin=fmts; run; data x; set one; array a[3] rating1-rating3; array fmt[3] $ 6 _temporary_ ('qrank.' 'rrank.' 'srank.'); array b[3] _temporary_; do _n_=1 to 3; if missing(a[_n_]) then continue; b[_n_]=inputn(a[_n_], fmt[_n_]); end; r_pct=put(min(of b , 24), rank2pct.); run;
... View more