LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1996, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Oct 1996 13:38:54 GMT
Reply-To:     Inus van Sandwyk <gnfmcmvs@FRM.UOVS.AC.ZA>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Inus van Sandwyk <gnfmcmvs@FRM.UOVS.AC.ZA>
Organization: University of Potchefstroom
Subject:      Re: howto: delete/keep obs with 2 byvars

Steven B. Isbell <sbi9477@tntech.edu> wrote in article <324BFC95.3301@tntech.edu>... > Data are sorted by two variables, X and Y. I want to output only the 5 > largest values of Y for each X. The number of observations of Y for each > X is not the same. The following does <i>not</i> work: > > PROC SORT; > BY X DESCENDING Y; > IF FIRST.X THEN DO; > IF _N_>5 THEN DELETE; > END; > IF LAST.X THEN OUTPUT; > > Anyone know how to do this? >

This is my solution : data i; input x y; cards; 1 11 1 12 1 13 1 14 1 15 1 16 1 17 2 21 2 22 2 23 2 24 2 25 2 26 2 27

;

proc sort; by x descending y;

data j; set i; by x descending y; if first.x then i = 1; else i + 1;

proc sort data = j (where = (i <= 5)); by x descending y;

proc print; run;

*Inus van Sandwyk;


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