Date: Thu, 13 May 2004 10:32:18 -0700
Reply-To: shiling zhang <shiling99@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: shiling zhang <shiling99@YAHOO.COM>
Organization: http://groups.google.com
Subject: Re: selecting top twovalues
Content-Type: text/plain; charset=ISO-8859-1
data t1;
input Hospital $10. Patient1 Patient2 Patient3;
cards;
Hospital1 20 5 10
Hospital2 2 1 50
Hospital3 23 40 1
;
data t2;
length Patient_name_2nd Patient_name_1st $10;
array p(3) Patient1 Patient2 Patient3;
set t1;
h1st=0; h2nd=0;
do i = 1 to dim(p);
if p(i) > h1st then do;
h2nd=h1st;
Patient_name_2nd=Patient_name_1st;
h1st=p(i);
Patient_name_1st=vname(p(i));
end;
else if p(i) > h2nd then do;
h2nd=p(i);
Patient_name_2nd=vname(p(i));
end;
end;
run;
proc print data=t2;
var Hospital Patient_name_1st h1st Patient_name_2nd h2nd;
run;
*****************listing********************;
Patient_ Patient_
Obs Hospital name_1st h1st name_2nd h2nd
1 Hospital1 Patient1 20 Patient3 10
2 Hospital2 Patient3 50 Patient1 2
3 Hospital3 Patient2 40 Patient1 23
Hope this helps
carter_51@HOTMAIL.COM (John Carter) wrote in message news:<200405130128.i4D1SjG00848@listserv.cc.uga.edu>...
> Hi all,
> Was wondering if someone could help me out on this:
>
> I have the following data (just an example):
>
>
> Patient1 Patient2 Patient3
> Hospital1 20 5 10
> Hospital2 2 1 50
> Hospital3 23 40 1
>
> Basically what I'm trying to do is to have a DATASET that has the highest
> two Patients from each hospital: example. Looking for a dataset, not a
> report output.
>
> Dataset:
>
> Hospital High Highnumvalue SecondHigh Secondhighvalue
>
> Hospital1 Patient1 20 Patient3 10
> Hospital2 Patient3 50 Patient1 2
> Hospital3 Patient2 40 Patient1 23
>
> Any help would be great.