data have;
input ID Year RxStart RxEnd DrugClass;
format RxStart RxEnd yymmdd10.;
datalines;
1 2009 17898 17928 0
1 2009 17898 17928 1
1 2009 18141 18171 0
1 2009 18171 18201 0
2 2009 18079 18115 1
2 2009 18110 18140 0
2 2009 18215 18230 1
2 2009 18220 18234 0
3 2009 18089 18125 0
3 2009 18126 18146 0
3 2009 18156 18186 1
3 2009 18186 18196 1
;
data want;
do until(last.id);
set have;
by id;
k=lag(rxend);
if first.id then do; flag=0;Day1stofOverlap=.;Overlap=0;end;
if id=lag(id) and lag(drugclass) ne drugclass and flag eq 0 and rxstart<k then do;
dif=k-rxstart;flag=1;
if not Day1stofOverlap then Day1stofOverlap=rxstart;
end;
else flag=0;
Overlap+dif;
call missing(dif);
end;
do until(last.id);
set have;
by id;
output;
end;
format Day1stofOverlap yymmdd10.;
drop k dif;
run;
A request plz:
If the above works or does not work let me know a feedback be it positive or negative. The logic was given to me by a Python expert college mate of mine by the name Mr. Jim Scully at DePaul university, Chicago. I merely translated his logic to SAS syntax. We look forward to your feedback for our continuous learning and improvement. Thank you
... View more