BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
justagba
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

justagba
Calcite | Level 5

Thank you so much   ballardw

 

 

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!

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
  • 2 replies
  • 381 views
  • 0 likes
  • 2 in conversation