I have a problem similar to the problem in -
https://communities.sas.com/t5/SAS-Programming/Concomitant-drug-medication-use/m-p/339879#M77587
However I have an issue , I have overlapping of same drug as well -
Eg:
ID | DRUG | START_DT | DAYS_SUPP | END_DT |
1 | A | 2/17/2010 | 30 | 3/19/2010 |
1 | A | 3/17/2010 | 30 | 4/16/2010 |
1 | A | 4/12/2010 | 30 | 5/12/2010 |
1 | A | 8/20/2010 | 30 | 9/19/2010 |
1 | B | 5/6/2009 | 30 | 6/5/2009 |
Here the three A prescriptions are over lapping .
So using the code in the link gives me combinations like A-A-B
whereas I dont want that.
However I want to account for the overlapping days for drug A. So I want to shift the second row prescription to 3/20/2010 to 4/19/2010. Similarly for 3rd A prescription.
@riya275 wrote:
I have a problem similar to the problem in -
https://communities.sas.com/t5/SAS-Programming/Concomitant-drug-medication-use/m-p/339879#M77587
However I have an issue , I have overlapping of same drug as well -
Eg:
ID DRUG START_DT DAYS_SUPP END_DT 1 A 2/17/2010 30 3/19/2010 1 A 3/17/2010 30 4/16/2010 1 A 4/12/2010 30 5/12/2010 1 A 8/20/2010 30 9/19/2010 1 B 5/6/2009 30 6/5/2009
Here the three A prescriptions are over lapping .
So using the code in the link gives me combinations like A-A-B
whereas I dont want that.
However I want to account for the overlapping days for drug A. So I want to shift the second row prescription to 3/20/2010 to 4/19/2010. Similarly for 3rd A prescription.
Try this:
data want;
set have;
prev_end_dt=lag(end_dt);
if start_dt<=prev_end_dt then start_dt=prev_end_dt+1;
drop prev_end_dt;
run;
This assumes that START_DT and END_DT are actual SAS date values, formatted as shown.
does not take into account the days of supply. His total days of supply will reduce this way
@riya275 wrote:
does not take into account the days of supply. His total days of supply will reduce this way
Please give an example.
Hi @riya275
Could you please test if the following approach meet your needs?
data have;
infile datalines dlm="09"x;
input ID DRUG $ START_DT: MMDDYY10. DAYS_SUPP END_DT:MMDDYY10.;
format START_DT END_DT MMDDYY10.;
datalines;
1 A 2/17/2010 30 3/19/2010
1 A 3/17/2010 30 4/16/2010
1 A 4/12/2010 30 5/12/2010
1 A 8/20/2010 30 9/19/2010
1 B 5/6/2009 30 6/5/2009
;
run;
proc sort data=have out=have_sorted;
by ID DRUG START_DT;
run;
data have2;
set have_sorted;
format NEW_START_DT NEW_END_DT _lagEND_DT MMDDYY10.;
_lagID = lag(ID);
_lagDRUG = lag(DRUG);
_lagEND_DT = lag(END_DT);
if ID = _lagID and DRUG = _lagDRUG and START_DT <= _lagEND_DT then flag=1;
else flag = 0;
retain NEW_START_DT NEW_END_DT;
if flag=0 then do;
NEW_START_DT = START_DT;
NEW_END_DT = END_DT;
end;
else do;
NEW_START_DT + DAYS_SUPP + 1;
NEW_END_DT + DAYS_SUPP + 1;
end;
drop flag _:;
run;
This gives incorrect results if the days_supp is different for rows. So I have modified it a bit -
data have2;
set have_sorted1;
format NEW_START_DT NEW_END_DT _lagEND_DT date9.;
_lagID = lag(patient_ID);
_lagDRUG = lag(drg_cls);
_lagEND_DT = lag(rx_ed_dt);
if patient_ID = _lagID and drg_cls= _lagDRUG and rx_st_dt <= _lagEND_DT then flag=1;
else flag = 0;
retain NEW_START_DT NEW_END_DT;
if flag=0 then do;
NEW_START_DT = rx_st_dt;
NEW_END_DT = rx_ed_dt;
end;
else do;
New_start_dt = NEW_End_DT + 1;
NEW_END_DT = new_start_dt + DAY_SUPP ;
end;
/* drop flag _:;*/
run;
But even then I get incorrect result -
Patient_id | Drug | drug_start | day_supp | drug_end | New_start | New_end |
15 | A | 6-Sep-15 | 30 | 5-Oct-15 | 6-Sep-15 | 5-Oct-15 |
15 | A | 24-Sep-15 | 90 | 22-Dec-15 | 6-Oct-15 | 4-Jan-16 |
15 | A | 6-Dec-15 | 90 | 4-Mar-16 | 5-Jan-16 | 4-Apr-16 |
15 | A | 26-Feb-16 | 90 | 25-May-16 | 5-Apr-16 | 4-Jul-16 |
15 | A | 29-May-16 | 90 | 26-Aug-16 | 29-May-16 | 26-Aug-16 |
15 | A | 7-Dec-16 | 90 | 6-Mar-17 | 7-Dec-16 | 6-Mar-17 |
15 | A | 17-Feb-17 | 90 | 17-May-17 | 7-Mar-17 | 5-Jun-17 |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.