recording Medication Treatment Segments

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

recording Medication Treatment Segments

Hello,

 

I am trying to write a program that will enable me to count medication segments by thousands of patients. An example:

let's say a patient fill a Rx for the months of January, February and March 2017 and stops. Then the same member resumes the same medication(s) for June and July 2017 and stops. He (possibly) comes back in November and continues to December 2017. This will be counted as 3 treatments segments. I understand that this particular patient may be a rare case but I will not be able to know for sure.

How can I code to obtain this count. I already performed the transpose of the data by Fill_date and by Days_Supply. I still have the raw data. I am using 9.2 Any help will be greatly appreciated.

 

Thanks


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 12,148

Re: recording Medication Treatment Segments

First is to insure that your date variables are all SAS date valued variables which are numeric and if they appear to be date have a SAS date related format. This is important as calculations of intervals or durations are simple with the SAS date valued variables but massive headaches otherwise (unless the values are turned into SAS date values).

 

You will have to clearly specify how long of an interval is required to be treated as a "segment break" or what ever you may think of that interval.

 

It helps if you can provide a little example data in the form of a data step so we don't have to guess about the content of the data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here may be something enough to get you started:

data need;
   set example;
   by id filldate;
   retain segment;
   lfd = lag(filldate);
   lds = lag(dayssupply);
   if first.id then do;
      daysbreak = 0;
      segment = 1;
   end;
   else daysbreak = filldate -(lfd+lds);
   if daysbreak> 0 then segment+1;
   drop lfd lds;
run;

if you need to track individual and differing medications they the sort would be by ID Medication Filldate, the by in the data step the same, and the If First.ID would become If first.medication.

 

 

The FIRST. variable indicator comes with use of BY group processing and each variable on the by statement, along with a LAST. to indicate the start and end of groups.

The Daysbreak variable in the data set need contains the number of days from the end of prior prescription fill + days supplied and the current fill date. If the value is negative or 0 then no break occurs.

View solution in original post


All Replies
Solution
2 weeks ago
Super User
Posts: 12,148

Re: recording Medication Treatment Segments

First is to insure that your date variables are all SAS date valued variables which are numeric and if they appear to be date have a SAS date related format. This is important as calculations of intervals or durations are simple with the SAS date valued variables but massive headaches otherwise (unless the values are turned into SAS date values).

 

You will have to clearly specify how long of an interval is required to be treated as a "segment break" or what ever you may think of that interval.

 

It helps if you can provide a little example data in the form of a data step so we don't have to guess about the content of the data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here may be something enough to get you started:

data need;
   set example;
   by id filldate;
   retain segment;
   lfd = lag(filldate);
   lds = lag(dayssupply);
   if first.id then do;
      daysbreak = 0;
      segment = 1;
   end;
   else daysbreak = filldate -(lfd+lds);
   if daysbreak> 0 then segment+1;
   drop lfd lds;
run;

if you need to track individual and differing medications they the sort would be by ID Medication Filldate, the by in the data step the same, and the If First.ID would become If first.medication.

 

 

The FIRST. variable indicator comes with use of BY group processing and each variable on the by statement, along with a LAST. to indicate the start and end of groups.

The Daysbreak variable in the data set need contains the number of days from the end of prior prescription fill + days supplied and the current fill date. If the value is negative or 0 then no break occurs.

Occasional Contributor
Posts: 5

Re: recording Medication Treatment Segments

Thank you so much   ballardw

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 94 views
  • 0 likes
  • 2 in conversation