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 (February 2012, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 23 Feb 2012 14:20:25 -0600
Reply-To:   "Data _null_;" <iebupdte@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Data _null_;" <iebupdte@GMAIL.COM>
Subject:   Re: outputting the next to last observation per group
Comments:   To: "Keintz, H. Mark" <mkeintz@wharton.upenn.edu>
In-Reply-To:   <E0B423A8C0D1E74B8905B2C5CB38C1AF02F9BECA@GENO4.wharton.upenn.edu>
Content-Type:   text/plain; charset=ISO-8859-1

I'm sorry to hear about your pointaphobia. Is it covered by your medical insurance?

The advantage of POINT in this example is that only the selected records are read twice. Which I suppose could provide a small performance advantage.

On 2/23/12, Keintz, H. Mark <mkeintz@wharton.upenn.edu> wrote: > Here's one that does the same, but indulges my compulsion to avoid the > POINT= option. > > If you don't want to output any records for cases with only 1 record in the > group (the singe age=16 in sashelp.class), then drop the "BY AGE" and "IF > FIRST.AGE=1..." statements. But keep the "SET AGE" statement. > > Regards, > Mark Keintz > > > data want ; > set have; > > by age; > ** Output singletons **; > if first.age=1 and last.age=1 then output; > > set have (firstobs=2 keep=age rename=(age=nextage)); > by nextage; > ** Now output next-to-last records **; > if last.nextage and age=nextage then output; > run; > > > > Mark Keintz > Wharton Research Data Services > 215/898-2160 > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Data > _null_; > Sent: Thursday, February 23, 2012 2:41 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: outputting the next to last observation per group > > Here AGE in SASHELP.CLSSS equal PERSON. > > When last is also first what do you want to do? I used last. > > proc sort data=sashelp.class out=class; > by age; > run; > proc print; > run; > data next2Last; > _n_ = 0; > do until(eof); > do _n_ = _n_+1 by 1 until(last.age); > set class(keep=age) end=eof; > by age; > end; > point = _n_-(last.age*not first.age); > obs = point; > set class point=point; > output; > call missing(of _all_); > end; > stop; > run; > proc print; > run; > > On 2/23/12, Alison <alisontetler@yahoo.com> wrote: >> Hi - I think this should be an easy task but can't quite get it. I >> have multiple observations per person (series of births) and want to >> select the next to last observation in the dataset per person. How do I >> do this?? >> Thanks! >> Alison >> >


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