LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (May 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 7 May 2008 13:16:43 -0400
Reply-To:     Nathaniel.Wooding@DOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject:      Re: How to find the first 5 and last 5 data?
In-Reply-To:  <d3de31ac0805070849i2829fd94x6b0acfa0ca70dcc@mail.gmail.com>
Content-Type: text/plain; charset="US-ASCII"

Jane

I just tried to reply to this but I don't think that it went out.

The following is an update to the code that I sent you last evening. I added a sort at the end which takes care of the situation of their being fewer than 10 obs.

Data one; input id var1 var3 ; cards; 1 2 21 1 3 56 1 7 35 1 8 98 1 9 22 1 6 11 1 4 11 1 4 10 1 3 2 1 4 6 1 3 18 2 1 1 2 2 2 2 3 3 2 4 4 2 5 5 2 6 6 proc print; run; Proc sort data = one out= two; by id var3; run; Proc sort data = one out = three; by id descending var3; run ;

Data two; set two; by id; if first.id then count=0; count+1; if count le 5; drop count; run;

Data three; if first.id then count=0; count+1; if count le 5; drop count; run; Data final; set two three; by id; run; Proc sort data = final nodupkeys;* this takes care of the situation when there are fewer than 10 obs; by id var1 var3; run; Proc print; run;

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

Jane <program.sas@GMAI L.COM> To Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU Discussion" cc <SAS-L@LISTSERV.U GA.EDU> Subject Re: How to find the first 5 and last 5 data? 05/07/2008 11:49 AM

Please respond to Jane <program.sas@GMAI L.COM>

It's for sure there have no tie for my data. Since it's the surgery time by different physicians. They can not do two surgeries in same time.

For the ID with less than 10 rows, I just want to pick the first 5 subjects and then the left subjects whatever it's less than 5 subjects.

On Wed, May 7, 2008 at 8:04 AM, Howard Schreier <hs AT dc-sug DOT org> < schreier.junk.mail@gmail.com> wrote:

> On Tue, 6 May 2008 15:45:04 -0400, Jane <program.sas@GMAIL.COM> wrote: > > >Hi All > > > >I have a question to find out the 1st and last 5 subjects according to > the > >rank of other variables. > > > >The dataset like: > > > >id var1 var3 > >----------------- > >1 2 21 > >1 3 56 > >1 7 35 > >1 8 98 > >...... > > > >I want to pick the 1st 5 and last 5 rows for var3 according to var1 for > each id. > > > >Hope I make the question clearly. Thanks all! > > > >Jane > > Is it possible that there will be ties, such as the 5th and 6th values of > VAR1 being the same? If so, what should be done? > > Is it possible that for some ID there will be fewer than 10 rows? If so, > what should be done? >

----------------------------------------- CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and/or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.


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