data test2;
retain num;
set test1;
by apply_no no;
if no=1 then do;
if first.no then num=1;
else num+1;
end;
else call missing(num);
run;
proc sort data=test2;
by id;
run;
data want;
set test2;
retain tmp tmp_on;
if not missing(num) then do;
tmp=num;
tmp_on=1;
end;
if missing(num) and dif(no)^=1 then tmp_on=0;
if missing(num) then num=(tmp*tmp_on)+(no*(1-tmp_on));
keep apply_no no num;
run;