data test;
informat usubjid $3. llt $5. ae $7. astdt date9. aendt date9.;
input usubjid $
ae $
llt $
astdt
aendt
;
format astdt aendt date9.;
datalines;
120 enzymes Lipa 21FEB2020 06MAR2020
120 enzymes Lipa 06MAR2020 13MAR2020
120 enzymes Serum 06MAR2020 13MAR2020
120 enzymes Lipa 09APR2020 21MAY2020
120 enzymes Serum 09APR2020 03JUN2020
120 enzymes Lipa 21MAY2020 01JUL2020
120 enzymes Serum 03JUN2020 01JUL2020
120 enzymes Lipa 01JUL2020 28JUL2020
120 enzymes Serum 01JUL2020 18NOV2020
120 enzymes Lipa 28JUL2020 26AUG2020
120 enzymes Lipa 26AUG2020 21OCT2020
120 enzymes Lipa 18NOV2020 15DEC2020
120 enzymes Amylase 18NOV2020 15DEC2020
120 enzymes Serum 15DEC2020 .
;
proc print;
run;
data want;
set test;
by usubjid ae;
length rank 8 maxrank 8;
retain rank;
if _n_ = 1
then do;
declare hash end ();
end.definekey("aendt","llt");
end.definedata("rank");
end.definedone();
end;
if first.usubjid then rank = 1;
else do;
if first.rank
then do;
rc = end.clear();
maxrank = 1;
rank = 1;
rc = end.add();
end;
else do;
if end.find(key:astdt,key:llt) ne 0
then do;
maxrank + 1;
rank = maxrank;
rc = end.add();
end;
else do;
if end.check() ne 0
then rc = end.add();
end;
end;
end;
drop rc maxrank;
proc print;
run;
Adapting @Kurt_Bremser 's code. shouldn't the last 3 rows be 5,6,7 for rank and not 6,5,7?
... View more