data a;
input company date:yymmn6. id;
format date yymmn6.;
if missing(id) then mis='yes';
else mis='no';
datalines;
1001 200509 2
1001 200510 6
1001 200511 2
1001 200512 6
1119 200112 .
1119 200201 .
1119 200202 6
1119 200203 8
;
run;
proc sort data=a;
by company mis date ;
run;
data a(drop=mis tempid);
set a;
by company mis date;
retain tempid;
if first.company then tempid=id;
id=tempid;
if mis='yes' then id=.;
run;
proc sort data=a;
by company date ;
run;