Date: Mon, 21 Jan 2008 06:05:18 -0800
Reply-To: Melodyp <pearsonmelody@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Melodyp <pearsonmelody@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Top 3 of by group
Content-Type: text/plain; charset=ISO-8859-1
On Jan 21, 12:34 am, ya.hu...@AMYLIN.COM (Ya Huang) wrote:
> proc sort data=have;
> by type counts descending sum;
> run;
>
> data need;
> set have;
> by type counts descending sum;
> if first.counts then n_=0;
> if first.sum then n_+1;
> if n_<=3 then output;
> run;
>
> TYPE counts SERVICE Sum n_
>
> A 216 A.6 44 1
> A 216 A.2 40 2
> A 216 A.1 19 3
> A 216 A.11 19 3
> A 216 A.12 19 3
> B 23 B.5 5 1
> B 23 B.6 4 2
> B 23 B.4 2 3
> B 23 B.7 2 3
> C 106 C.1 22 1
> C 106 C.5 18 2
> C 106 C.9 14 3
>
> On Sun, 20 Jan 2008 23:16:05 -0500, Thien <coithienthai2...@YAHOO.COM.AU>
> wrote:
>
>
>
> >Hello SAS users I have a simple question which I need your help.
>
> >The data set I have is below and I'm tryng to select the top 3 Service's
> >Sum which can have more than 3 records if ties is present. Much
> >appreciated for your help.
>
> >INPUT DATA SET OUTPUT DATA SET
>
> >TYPE counts SERVICE Sum TYPE counts SERVICE Sum
> >A 216 A.1 19 A 216 A.1 19
> >A 216 A.2 40 A 216 A.2 40
> >A 216 A.3 16 A 216 A.6 44
> >A 216 A.4 7 A 216 A.11 19
> >A 216 A.5 11 A 216 A.12 19
> >A 216 A.6 44 B 23 B.4 2
> >A 216 A.7 3 B 23 B.5 5
> >A 216 A.8 7 B 23 B.6 4
> >A 216 A.9 1 B 23 B.7 2
> >A 216 A.10 2 C 106 C.1 22
> >A 216 A.11 19 C 106 C.5 18
> >A 216 A.12 19 C 106 C.9 14
> >B 23 B.1 1
> >B 23 B.2 1
> >B 23 B.3 1
> >B 23 B.4 2
> >B 23 B.5 5
> >B 23 B.6 4
> >B 23 B.7 2
> >B 23 B.8 1
> >B 23 B.9 1
> >B 23 B.10 1
> >B 23 B.11 1
> >B 23 B.12 1
> >B 23 B.13 1
> >B 23 B.14 1
> >C 106 C.1 22
> >C 106 C.2 7
> >C 106 C.3 2
> >C 106 C.4 7
> >C 106 C.5 18
> >C 106 C.6 8
> >C 106 C.7 11
> >C 106 C.8 9
> >C 106 C.9 14
> >C 106 C.10 2
> >C 106 C.11 6- Hide quoted text -
>
> - Show quoted text -
I am very new to SAS, could you explain this code a little bit?
like .count or n_?
Thank you,
Melody
|