Thank you for supplying your sample data as a working DATA step. I don't see a similar sample of the corresponding expected output, but I suspect this is what you want:
data _1;
infile datalines dsd truncover;
INPUT Level:8. F_there:$1. Blank_90:8.;
DATALINES ;
1,x,20
2,x,20
3,F,29
3,F,
4,F,
4,s,90
5,s,
5,s,91
3,F,90
3,s,3
4,s,30
3,S,30
1,X,20
2,X,20
3,X,20
3,S,20
4,F,91
4,F,90
5,,90
6,F,
7,F,
4,,10
3,S,20
1,,20
;;
RUN;
data want (drop=_:);
set _1;
retain status ' ' /* Either "NA" or 2 blanks */
_terminate_level . /* Level which will return status to blank */
_countdown . /* 1 means the following obs starts status="NA" */;
if _countdown=1 then do; /* Start NA status */
status='NA';
_countdown=.;
end;
else if status=' ' and level>2 and blank_90 in (.,90) then do;
_terminate_level=level;
_countdown=1;
end;
else if level=_terminate_level then call missing(of _:,status);
run;
... View more