BookmarkSubscribeRSS Feed
riya275
Obsidian | Level 7

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:

IDDRUGSTART_DTDAYS_SUPPEND_DT
1A2/17/2010303/19/2010
1A3/17/2010304/16/2010
1A4/12/2010305/12/2010
1A8/20/2010309/19/2010
1B5/6/2009306/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. 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
riya275
Obsidian | Level 7

 does not take into account the days of supply. His total days of supply will reduce this way

PaigeMiller
Diamond | Level 26

@riya275 wrote:

 does not take into account the days of supply. His total days of supply will reduce this way


Please give an example.

--
Paige Miller
ed_sas_member
Meteorite | Level 14

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;

 Capture d’écran 2020-02-26 à 15.02.43.png

 

riya275
Obsidian | Level 7

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_idDrugdrug_startday_suppdrug_endNew_startNew_end
15A6-Sep-15305-Oct-156-Sep-155-Oct-15
15A24-Sep-159022-Dec-156-Oct-154-Jan-16
15A6-Dec-15904-Mar-165-Jan-164-Apr-16
15A26-Feb-169025-May-165-Apr-164-Jul-16
15A29-May-169026-Aug-1629-May-1626-Aug-16
15A7-Dec-16906-Mar-177-Dec-166-Mar-17
15A17-Feb-179017-May-177-Mar-175-Jun-17

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 960 views
  • 0 likes
  • 3 in conversation