proc sort data=indata out=uniqueid(keep=id) nodupkey;
by id;
run;
data shell;
set uniqueid;
do x=2002 to 2008;
output;
end;
run;
** sort indata and shell by id x;
data temp;
merge indata shell;
by id x;
retain IND_;
if first.id then do;
ind_=0;
end;
if y=0 then do;
IND=1;
ind_=1;
end;
if y=. then do;
if ind_=0 then ind=0;
if ind_=1 then ind=1;
end;
if y=1 then do;
ind=1;
ind_=0