|
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
>>
>
|