data have;
input id $ group;
cards;
a 1
a 1
a .
a 1
a 1
b 1
b .
b 1
b 1
b .
b 1
c .
c .
c 1
c .
c .
c 1
c 1
;
data wanted;
set have;
by id;
retain missflag temp;
if first.id then temp=^missing(group);
if missing(group) then missflag=1;
else do;
if missflag=1 then do;
temp+1;
missflag=0;
end;
new_group=temp;
end;
drop missflag temp;
run;