BookmarkSubscribeRSS Feed
ssitharath0420
Quartz | Level 8

Hello,

 

I am trying to determine the best procedure to determine the days covered within a year (2016) for each therapy.  I also need to determine whether the therapy is a addition addon by the prescriber or whether they switch to a new therapy.

 

Output needed:

 

Patid,Therapy,Daycovered (take intoconsideration of overlapping), Class (Mono Addon Switch)

 

Any helps would be appreciated!

 

This is the data:

PATIDTherapyserv_date1serv_date2serv_date3serv_date4serv_date5days_supply1days_supply2days_supply3days_supply4days_supply5
1A1/11/20164/13/20167/18/201610/28/2016 90909090 
1B6/18/20169/22/201612/13/201612/28/2016 90903030 
2A1/11/20164/18/20167/14/201610/13/2016 90909090 
2B1/11/20164/16/20167/18/201610/13/201611/22/20169090909090
3A3/2/20168/29/201611/5/2016  909090  
3B2/5/20166/28/20169/6/201612/2/2016 90909090 
3C3/26/20166/27/20169/6/201611/29/2016 90909090 
4A1/1/20164/1/20164/13/201612/31/2016 90909030 

 

 

 

 

 

 

22 REPLIES 22
mkeintz
PROC Star

And how about showing a table of expected output?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ssitharath0420
Quartz | Level 8

The output table should be:

 

Patid, therapy,dayscovered, class (mono,addon,switch)

ssitharath0420
Quartz | Level 8

Hi,

 

Please find the sample output

 

PATIDTherapyDays_CoveredClass
1A355First Therapy
1B190AddOn
2A347First Therapy
2B346AddOn
3A214AddOn
3B276First Therapy
3C277AddOn
4A180Mono
5A120First Therapy
5B120Switched
ballardw
Super User

Are your date variables SAS date values or character variables?

It will also help if you define "days covered" in terms of the variables presented. I might make a guess and sometimes be right but you might have rules that are not obvious.

 

It really helps to provide data in the form of a data step. You can follow instruction here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to generate datastep code from a SAS data set. That will completely describe your data and provide data that we can test code against.

 

ssitharath0420
Quartz | Level 8

I am downloaded the macro but can't get it to create a data step.  The date is mmddyy10. format.  DayCovered is how many days are covered for these therapy within 365 days for 2016.

ballardw
Super User

Walking through how to define something interms of variables:

You know what 'days covered' means. I see 5 date variables and 5 variables called "days_supply".

Is the "days covered" associateed with PatId=1 ant Therapy='A' the number of days between serv_date1 and servdate2? Or does it have some relationship to days_supply1? Or are we supposed to "know" that 1/11/2016 to 4/10/2016 are "covered" because of the days_supply?  And since you have serv_date2 of 4/13/2016 how does the gap get considered? Are we supposed to calculate consecutive days or total days within a calendar year.

Note that having the "days_supply" value EXACTLY the same for every record means it is pretty much not needed. If it varies then you need to show some examples.

 

Are we supposed to only consider one therapy at a time or are you looking to summarize across multiple therapies?

And how do you want "take into consideration of overlapping"? Set a report flag that a period overlapped? Indicate how many days overlapped?

 

You should show what a hand calculated result should look like for at least a couple of cases. Including one the has varying "days_supply" values.

 

You  say the output table should have:

The output table should be:

 

Patid, therapy,dayscovered, class (mono,addon,switch). Without knowing whether the output should only have one record per patient or not, it is kind of difficult to know where we are placing a "class" variable. That is why we asked for an example of the output, not a list of the variables.

ssitharath0420
Quartz | Level 8

Hi.  Please find the attached datastep for the sample data.

 

data WORK.TESTING;
  infile datalines dsd truncover;
  input PATID:32. Therapy:$1. serv_date1:DATE9. serv_date2:DATE9. serv_date3:DATE9. serv_date4:DATE9. serv_date5:DATE9. days_supply1:32. days_supply2:32. days_supply3:32. days_supply4:32. days_supply5:32.;
datalines4;
1,A,11JAN2016,13APR2016,18JUL2016,28OCT2016,,90,90,90,90,
1,B,18JUN2016,22SEP2016,13DEC2016,28DEC2016,,90,90,30,30,
2,A,11JAN2016,18APR2016,14JUL2016,13OCT2016,,90,90,90,90,
2,B,11JAN2016,16APR2016,18JUL2016,13OCT2016,22NOV2016,90,90,90,90,90
3,A,02MAR2016,29AUG2016,05NOV2016,,,90,90,90,,
3,B,05FEB2016,28JUN2016,06SEP2016,02DEC2016,,90,90,90,90,
3,C,26MAR2016,27JUN2016,06SEP2016,29NOV2016,,90,90,90,90,
4,A,01JAN2016,01APR2016,13APR2016,31DEC2016,,90,90,90,30,
5,A,01JAN2016,01FEB2016,01MAR2016,01APR2016,,30,30,30,30,
5,B,01MAY2016,01JUN2016,01JUL2016,01AUG2016,,30,30,30,30,
;;;;

 

Below is the needed Output:

 

PATIDTherapyDays_CoveredClass
1A355First Therapy
1B190AddOn
2A347First Therapy
2B346AddOn
3A214AddOn
3B276First Therapy
3C277AddOn
4A180Mono
5A120First Therapy
5B120Switched
HB
Barite | Level 11 HB
Barite | Level 11
data WORK.TESTING;
	infile datalines dsd truncover;
	input PATID:32. Therapy:$1. serv_date1:DATE9. serv_date2:DATE9. serv_date3:DATE9. 
	serv_date4:DATE9. serv_date5:DATE9. days_supply1:32. days_supply2:32. 
	days_supply3:32. days_supply4:32. days_supply5:32.;
datalines4;
1,A,11JAN2016,13APR2016,18JUL2016,28OCT2016,,90,90,90,90,
1,B,18JUN2016,22SEP2016,13DEC2016,28DEC2016,,90,90,30,30,
2,A,11JAN2016,18APR2016,14JUL2016,13OCT2016,,90,90,90,90,
2,B,11JAN2016,16APR2016,18JUL2016,13OCT2016,22NOV2016,90,90,90,90,90
3,A,02MAR2016,29AUG2016,05NOV2016,,,90,90,90,,
3,B,05FEB2016,28JUN2016,06SEP2016,02DEC2016,,90,90,90,90,
3,C,26MAR2016,27JUN2016,06SEP2016,29NOV2016,,90,90,90,90,
4,A,01JAN2016,01APR2016,13APR2016,31DEC2016,,90,90,90,30,
5,A,01JAN2016,01FEB2016,01MAR2016,01APR2016,,30,30,30,30,
5,B,01MAY2016,01JUN2016,01JUL2016,01AUG2016,,30,30,30,30,
;;;;
run;

*assume days_covered is a simple last therapy date minus first therapy date 
 since OP is unclear and provides no instructions for calculating days_covered
 also use a brute force method assuming only 5 service dates since OP provides 
 no inoformation regarding how many possible service dates there might be;
data testing;
	set testing;
	days_covered = 0;
	if serv_date2 then days_covered = serv_date2 - serv_date1;
	if serv_date3 then days_covered = serv_date3 - serv_date1;
	if serv_date4 then days_covered = serv_date4 - serv_date1;
	if serv_date5 then days_covered = serv_date5 - serv_date1;
run;

proc sort data = testing;
	by patid descending days_covered ;
run;

data testing;
	set testing;
	by patid;
	class = 'Unknown         ';
	if first.patid then class = 'First Therapy';
		else class = 'Add on';
	if first.patid and last.patid then class = 'Mono';
	keep patid therapy days_covered class;
run;
 

Output set is:

 

PATID Therapy days_covered class
1 A 291 First Therapy
1 B 193 Add on
2 B 316 First Therapy
2 A 276 Add on
3 B 301 First Therapy
3 A 248 Add on
3 C 248 Add on
4 A 365 Mono
5 B 92 First Therapy
5 A 91 Add on

 

 

Edit:

 

You may need to sort by serv_date1 as well

      by patid serv_date1 descending days_covered ;

 

This would be to cover situations where a therapy which had a larger days_covered number but started after a different therapy isn't classed as first therapy.  Assumes the therapy with the earliest serv_date regardless of length is the first therapy, and one that started after, even if it ran longer, is an add on.  

mkeintz
PROC Star

I doubt if this is the intended result

:

  1. It includes dates in 2017  (OP asked for "within a year (2016)").

  2. It double counts days in 2016 in which therapies overlap  (after all  there is the OP's ambiguous request to "take into consideration overlapping"). 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
HB
Barite | Level 11 HB
Barite | Level 11

mkeintz writes:

 



I doubt if this is the intended result

:

  1. It includes dates in 2017  (OP asked for "within a year (2016)").

  2. It double counts days in 2016 in which therapies overlap  (after all  there is the OP's ambiguous request to "take into consideration overlapping"). 

 


 

You may very well be correct.  Hard to say based on the info provided.

 

ssitharath0420
Quartz | Level 8

Yes, my timeframe is from 01/01/2016 to 12/31/2016.  So patient can potenially have a filled date up to 12/31/2016.

 

An example of how days covered should be calculated for 1A:

startGo to dateDayCovered
1/11/20164/10/201690
4/13/20167/12/201690
7/18/201610/16/201690
10/28/201612/31/201664
 Days Covered334
ssitharath0420
Quartz | Level 8

Patient 5 should be classify as "Switch"  because they took Therapy A from 01/01/2016 to 04/01/2016.  Then they completely stop it and resume again with a new therapy B from 05/01/2016 and on.

mkeintz
PROC Star

Please  tell us how you got 355 for the 1A record.  You will then likely have a well-defined problem for which a well-constructed solution can probably come back in reasonable time.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ssitharath0420
Quartz | Level 8

I am sorry.  It should 334.  The 335 comes from the first filled 01/01/2016 and subtracting that from 12/31/2016.

 

This is how days supply should be calculated.  An example of Patient ID 1 Therapy A:

 

startGo to dateDayCovered
1/11/20164/10/201690
4/13/20167/12/201690
7/18/201610/16/201690
10/28/201612/31/201664
 Days Covered334

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 22 replies
  • 1035 views
  • 0 likes
  • 4 in conversation