```Date: Thu, 28 May 2009 14:35:00 -0400 Reply-To: Chang Chung Sender: "SAS(r) Discussion" From: Chang Chung Subject: Re: Create Variables based on 5 other Numeric variables (decending order across) Comments: To: theepz.info@GOOGLEMAIL.COM On Thu, 28 May 2009 08:21:16 -0700, theepz.info@googlemail.com wrote: ... >I need to create New varables (T1-T5) based on V1-V5, answer should >be > >ID V1 V2 V3 V4 V5 T1 T2 T3 T4 T5 >11 5 4 7 3 2 V3 V1 V2 V4 V5 >22 3 3 4 2 1 V3 V1 V2 V4 V5 hi, Tz, yet another datastep solution. very inefficient! this one probably needs 9.2 since I am using "of arr[*]" notation when arr is a temporary array. hth. cheers, chang /* test data */ data one; input id v1-v5; cards; 11 5 4 7 3 2 22 3 3 4 2 1 33 9 8 7 1 5 ; run; data two; set one; array v[1:5] v1-v5; array t[1:5] \$ t1-t5; array i[1:5] _temporary_ (1,2,3,4,5); do k=1 by 1 until(v[i[1]]>=v[i[2]]>=v[i[3]]>=v[i[4]]>=v[i[5]]); call allperm(k,of i[*]); end; do k = 1 to 5; t[i[k]]=vname(v[k]); end; run; /* check */ data _null_; set two; put id=/+3"v:"(v1-v5)(3.)/+3"t:"(t1-t5)(\$3.-r); run; /* on log id=11 v: 5 4 7 3 2 t: v2 v3 v1 v4 v5 id=22 v: 3 3 4 2 1 t: v2 v3 v1 v4 v5 id=33 v: 9 8 7 1 5 t: v1 v2 v3 v5 v4 */ ```

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