```Date: Thu, 28 May 2009 13:18:02 -0400 Reply-To: msz03@albany.edu Sender: "SAS(r) Discussion" From: Mike Zdeb Subject: Re: Create Variables based on 5 other Numeric variables (decending order across) Content-Type: text/plain;charset=iso-8859-1 hi ... another idea, one data step it'd be easier without duplicate values of V within an ID since there'd be no reason to insert blanks in ALL anyways ... data a; input ID V1-V5; cards; 11 5 4 7 3 2 22 3 3 4 2 1 run; data b; set a; array v(5); array t(5) \$2; all = cat(of v1-v5); do _n_ = 1 to 5; loc = find(all,cat(largest(_n_,of v1-v5))); substr(all,loc,1) = ' '; t(_n_) = cat('V',loc); end; drop loc all; run; proc print data=b; run; -- Mike Zdeb U@Albany School of Public Health One University Place Rensselaer, New York 12144-3456 P/518-402-6479 F/630-604-1475 > On 5/28/09, Nat Wooding wrote: >> This could be done with an array but a very simple solution (from a coding >> standpoint) that can work with any number of variables uses a couple >> Transposes , a sort. and a merge. > > Using Nat's approach plus PROC SUMMARY's IDGROUP option the desired > result could be achieved with one TRANSPOSE and one SUMMARY. For a > list of 100 variables or less. > > > data a; > input ID V1 V2 V3 V4 V5; > cards; > 11 5 4 7 3 2 > 22 3 3 4 2 1 > run; > proc transpose out=b; > by id; > var v:; > run; > proc summary data=b nway; > class id; > output out=c(drop=_type_ _freq_) > idgroup(max(col1) out[5](col1 _name_)=DV T) > idgroup(out[5](col1)=V) > ; > attrib > dv: label='Descending values of V' > t: label='Variable names of descending values of V' > v: label='Original values of V' > ; > run; > proc contents varnum; > run; > proc print; > run; > ```

Back to: Top of message | Previous page | Main SAS-L page