Hello everyone, thank you for your suggestions. After looking at my data, it turns out that I will need to flag baseline records by subject, test (i.e. glucose, albumin etc.) and category (chemistry, hematology, urinalysis, serology etc.), Date values are in character format. My output sample data is attached. The code I am working on is below, but it doesn't quite do what I want. It is flagging all dates prior to exposure by test category, but I only need the latest (or first.lbcat), and I have not been able to get it to flag correctly. data lbflag;
set _lbflag;
by usubjid lbtest lbcat descending lbdtc;
retain flag;
if first.lbtest then flag=0;
*** flag test dates prior to exposure ;
if flag=0 and lbdtc <= rfxstdtc and lbstat ~='NOT DONE' then flag=1 ;
*** if test is prior to exposure, flag by lbcat ;
if flag=1 then do;
retain _flag ;
if first.lbcat then _flag=0;
if lbdtc <= rfxstdtc
then do ;
_flag=1 ;
lbblfl = 'Y' ;
end;
end;
run;
... View more