Date: Tue, 1 Feb 2000 02:09:22 -0500
Reply-To: "Paul M. Dorfman" <sashole@MEDIAONE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Paul M. Dorfman" <sashole@MEDIAONE.NET>
Subject: Re: Array Question
Content-Type: text/plain; charset=us-ascii
Matt,
In your simple case, the most primitive array manipulation will suffice:
7 data _null_;
8 format c1-c5 s1-s5 z2.;
9 set one;
10 array c(5);
11 array s(5);
12 array z(0:1,11:52) _temporary_;
13 put 'original array..............: ' c1--c5;
14 do i=1 to 5;
15 z(0,c(i)) ++ 1;
16 z(1,c(i)) = i;
17 end;
18 do i=52 to 11 by -1;
19 do while (z(0,i) gt 0);
20 p ++ 1;
21 z(0,i) +- 1;
22 s(p) = i;
23 c(z(1,i)) = p;
24 end;
25 end;
26 put 'ranks of original array.....: ' c1--c5;
27 put 'sorted array................: ' s1--s5;
28 run;
original array..............: 11 52 44 21 37
ranks of original array.....: 05 01 02 04 03
sorted array................: 52 44 37 21 11
However, if you want to account for ties, as Macro Maven has pointed out, you will need to move to a more
elaborate scheme.
Kind regards,
=====================
Paul M. Dorfman
Jacksonville, Fl
=====================
MattFlynn wrote, in part:
> Given an array or list of variables, is there a simple/elegant way to sort/rank the five values of the array,
> while identifying the relative position of each? For example:
>
> data one;
> input c1 c2 c3 c4;
> array c (5) c1-c5;
> cards;
> 11 52 44 21 37
> ;
> /*********
> Desired example output:
> 52 44 37 21 11 (sorted high to low)
> c1 c2 c3 c4 c5
> 5th 1st 2nd 4th 3rd ( ID relative rank)
> ***********/
>
|