From: stats analysis on
Hi all,

I have the following dataset:

ID event
2 0
2 0
2 0
2 .
2 1
2 1
2 1

I need to delete all observation after the event occurs (after the 1)
that is.
so the data should look like this:

ID event
2 0
2 0
2 0
2 .
2 1
2 .
2 .

I tried flagging and using the retain code but it doesn't seem to
work.

data want;
set have;
by id;
retain flag 0;

if first.id then flag=0;
if flag=0 and event=1 then flag=1;
if first.id and flag=1 then event=.;
run;

any ideas would be great

thanks....
From: Arthur Tabachneck on
I think that the following does what you want to accomplish:

data have;
input ID event;
cards;
2 0
2 0
2 0
2 .
2 1
2 1
2 1
;

data want (drop=gotevent);
set have;
retain gotevent;
by id event notsorted;
if first.event then gotevent=0;
if not(gotevent) then do;
output;
end;
else do;
call missing(event);
output;
end;
if first.event and event eq 1 then gotevent=1;
run;

HTH,
Art
-------------
On Aug 2, 6:34 pm, stats analysis <statsfor...(a)gmail.com> wrote:
> Hi all,
>
> I have the following dataset:
>
> ID     event
> 2         0
> 2         0
> 2         0
> 2         .
> 2         1
> 2         1
> 2         1
>
> I need to delete all observation after the event occurs (after the 1)
> that is.
> so the data should look like this:
>
> ID     event
> 2         0
> 2         0
> 2         0
> 2         .
> 2         1
> 2         .
> 2         .
>
> I tried flagging and using the retain code but it doesn't seem to
> work.
>
> data want;
> set have;
> by id;
> retain flag 0;
>
> if first.id then flag=0;
> if flag=0 and event=1 then flag=1;
> if first.id and flag=1 then event=.;
> run;
>
> any ideas would be great
>
> thanks....