data had2(drop=day status flag status1);
set had;
retain flag;
by id day;
time2event=lag(day);
status1=lag(status);
if first.id then do;
status1=.;
flag=0;
end;
if status1=1 and status=1 then do;
censored=0;
output;
flag=1;
end;
if last.id and flag=0 then do;
time2event=day;
censored=1;
output;
end;
run;