|
Hi,
It should be done like this:
data d1;
input id $ x y z w;
cards;
1 1 3 4 6
1 4 8 9 0
2 22 44 44 8
2 23 34 45 8
2 12 3 4 7
;
run;
proc sort data=d1;
by id x;
run;
data sub_d1;
set d1;
by id x;
if (first.id and first.x);
run;
Daniel Fernandez.
Barcelona.
-----Mensaje original-----
De: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] En nombre de gupt
Enviado el: dimarts, 27 / octubre / 2009 07:51
Para: SAS-L@LISTSERV.UGA.EDU
Asunto: Re: how to get first obs from datasets sorted by two variables?
On Oct 26, 9:35 pm, muthia.kachira...@GMAIL.COM (Muthia Kachirayan)
wrote:
> Try
>
> data sub_d1;
> set d1;
> BY ID;
> if first.id=1 and ... /* what should i do here*/
>
> On Mon, Oct 26, 2009 at 12:17 PM, Jeff <zhuj...@gmail.com> wrote:
> > I have a dataset d1:
> > id x y z w
> > 1 1 3 4 6
> > 1 4 8 9 0
> > 2 22 44 44 8
> > 2 23 34 45 8
> > 2 12 3 4 7
> > ;
>
> > which is sorted by two variables id and x in ascending order.
> > I want to get the first obs after sorting,
> > which is:
> > id x y z w
> > 1 1 3 4 6
> > 2 12 3 4 7
>
> > I tried
> > proc sort data=d1;
> > by id x;
> > run;
>
> > data sub_d1;
> > set d1;
> > if first.id=1 and ... /* what should i do here*/
>
> > Thanks,
> > Jeff
Hi, Jeff,
Your question is not clear, on what basis you are choosing the
observations.
|