Michelle Good job of checking the output data. I see the problem and am busy today but I will keep working on it. Jim
Thank Jim!
Michelle Try this code. It doesn't concentrate on how many drug overlaps per day but which type of overlap occurred. It there were 5 overlaps of drug type A It shows an overlap of type A. If there was 5 drug A overlaps on a certain day and 1 B drug on the same day, it would report a type A overlap and a type A&B overlap. Jim
** expand each date range to one record per day;
data one;
input id type $ drug $ (begin_date end_date) (: mmddyy12.);
format begin_date end_date ondate mmddyy10.;
* put out a record for each day on the drug by type;
ondate=begin_date;
do until (ondate=end_date);
output; ondate+1;
end;
output; drop begin_date end_date;
cards;
1 a drug1 03/01/14 03/10/14
1 a drug1 03/11/14 03/20/14
1 a drug1 03/25/14 04/05/14
1 a drug2 03/02/14 03/09/14
1 a drug2 03/17/14 03/24/14
1 a drug2 03/27/14 04/04/14
1 a drug3 09/02/14 09/09/14
1 b drug4 03/01/14 03/10/14
1 b drug4 03/11/14 03/20/14
1 b drug4 03/25/14 04/05/14
1 b drug5 09/02/14 09/09/14
2 a drug1 03/01/14 03/10/14
2 a drug1 03/11/14 03/20/14
2 a drug1 03/25/14 04/05/14
2 a drug2 03/02/14 03/09/14
2 a drug2 03/17/14 03/24/14
2 a drug2 03/27/14 04/04/14
2 a drug3 09/02/14 09/09/14
;
** sort by day to see how many drugs taken each day ;
proc sort; by id ondate type drug ;
proc print; by id ondate; id id ondate ;
title 'how many drugs taken each day'; run;
* count number of drugs taken each day by id type;
* collapse to one record per string of days;
data; set; by id ondate; * type drug ; retain typa typb;
if first.ondate then do; count=0; typa=0; typb=0; end;
if type='a' then typa+1;
if type='b' then typb+1;
count+1;
if last.ondate and count gt 1 then do;
if typa and typb then do; olap='A&B'; output; end;
if typa gt 1 then do; olap='A'; output; end;
if typb gt 1 then do; olap='B'; output; end;
end;
drop drug type typa typb;
proc sort; by id olap ondate;
proc print; id id olap ondate;
title 'Collapse by date and type where multiple drugs taken'; run;
** step 3 identify the string of contiguous days (episode);
data; set; by id olap;
dif=ondate-lag(ondate);
retain flag strtdate;
format strtdate mmddyy10.;
if first.olap then do;
contdys=0; flag=0; dif=1; strtdate=ondate;
end;
if dif=1 then contdys+1;
else do; ** end of continuous string;
dif=1; strtdate=ondate;
contdys=1;
end;
drop dif flag count;
proc print; id id olap strtdate ondate contdys olap ;
by id olap strtdate;
title 'See episode data overlap of drugs and type'; run;
***step 4 see if the continuous string of days was gt 5;
data; set; by id olap strtdate;
drop ondate ;
if last.strtdate then do;
if contdys gt 5 then output;
end;
proc print split='*';
label id='id*' strtdate='episode*start date'
contdys='continous* days' olap='type';
id id strtdate contdys olap; by id; run;
*/;
Hi Jim, Thanks so much!!!!!!!!!!!!!!!!!! You are the super!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.