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

I have the following data in the table:

IDRx DtNext Rx DtDays SupplyBase date for Persistence
1231/31/20133/5/2013304/1/2013
1233/5/20134/3/2013305/4/2013
1234/3/20135/1/2013306/2/2013
1235/1/20136/5/2013306/30/2013
1236/5/20137/3/2013308/4/2013
1237/3/20138/2/2013309/1/2013
1238/2/20131/28/20143010/1/2013
1231/28/20142/26/2014303/29/2014
1232/26/20143/26/2014304/27/2014
1233/26/20144/25/2014305/25/2014
1234/25/20146/25/2014306/24/2014
1236/25/20147/22/2014308/24/2014
1237/22/201410/25/2014309/20/2014

What I have to do is check if Next Rx dt  < Base date for Persistence.  If it is TRUE then count as Therapy = 1 and Days on Therapy = 30.  If the next record is TRUE again then Therapy = 1 and Days on Therapy = 60 and so on until I find a record where Next Rx dt  < Base date for Persistence = FALSE. Then Therapy = .  and Days on Therapy = . If for the following record, Next Rx dt  < Base date for Persistence = TRUE then it will have Therapy =2 and Days of Supply =30. Next Record if it is TRUE then Therapy = 2 and Days of Supply = 60 and so on...  After that I want Persitent Flag  = 'Y' for each last record of the Therapy.

My Output should look like below:

IDRx DtNext Rx DtDays SupplyBase date for Persistence Is Next Rx date < Base dateTherapy  Days on TherapyPersitent Flag
1231/31/20133/5/2013304/1/2013TRUE130
1233/5/20134/3/2013305/4/2013TRUE160
1234/3/20135/1/2013306/2/2013TRUE190
1235/1/20136/5/2013306/30/2013TRUE1120
1236/5/20137/3/2013308/4/2013TRUE1150
1237/3/20138/2/2013309/1/2013TRUE1180Y
1238/2/20131/28/20143010/1/2013FALSE
1231/28/20142/26/2014303/29/2014TRUE230
1232/26/20143/26/2014304/27/2014TRUE260
1233/26/20144/25/2014305/25/2014TRUE290Y
1234/25/20146/25/2014306/24/2014FALSE
1236/25/20147/22/2014308/24/2014TRUE330Y
1237/22/201410/25/2014309/20/2014FALSE

I would appreciate any help in this.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Maybe the sooner you wrap up this thread:

the sooner you will get responses?

View solution in original post

7 REPLIES 7
pp2014
Fluorite | Level 6

Any help please...

Haikuo
Onyx | Level 15

Maybe the sooner you wrap up this thread:

the sooner you will get responses?

pp2014
Fluorite | Level 6

Little changes to my earlier post.  I do not need Persistent Flag.  I need cummulative days between the Refill if the Patient is on Therapy.  Below is the data I have :

IDRx DtNext Rx DtDays SupplyDays between next refillBase date for Persistence
1231/31/20133/5/201330334/1/2013
1233/5/20134/3/201330295/4/2013
1234/3/20135/1/201330286/2/2013
1235/1/20136/5/201330356/30/2013
1236/5/20137/3/201330288/4/2013
1237/3/20138/2/201330309/1/2013
1238/2/20131/28/201430 10/1/2013
1231/28/20142/26/201430293/29/2014
1232/26/20143/26/201430284/27/2014
1233/26/20144/25/201430305/25/2014
1234/25/20146/25/201430 6/24/2014
1236/25/20147/22/201430278/24/2014
1237/22/201410/25/201430 9/20/2014

My Final Output looks like below:

IDRx DtNext Rx DtDays SupplyDays between next refillBase date for Persistence Is Next Rx date < Base dateTherapy  Days on Therapy(Cumm.)
1231/31/20133/5/201330334/1/2013TRUE133
1233/5/20134/3/201330295/4/2013TRUE162
1234/3/20135/1/201330286/2/2013TRUE190
1235/1/20136/5/201330356/30/2013TRUE1125
1236/5/20137/3/201330288/4/2013TRUE1153
1237/3/20138/2/201330309/1/2013TRUE1183
1238/2/20131/28/201430 10/1/2013FALSE
1231/28/20142/26/201430293/29/2014TRUE229
1232/26/20143/26/201430284/27/2014TRUE257
1233/26/20144/25/201430305/25/2014TRUE287
1234/25/20146/25/201430 6/24/2014FALSE
1236/25/20147/22/201430278/24/2014TRUE327
1237/22/201410/25/201430 9/20/2014FALSE

NOTE:  Cumm. Days on Therapy is nothing but Cumm. Days between each refill for each Therapy

If the Patient is on Therapy first time then Therapy = 1. It will continue to be 1 until Is Next Rx date <  Base date = FALSE.  During that time you should do the cummulative Days on Therapy.   When you see the next  Is Next Rx date <  Base date = TRUE then Therapy becomes 2 and .Start doing cummulative Days on Therapy  from that point on until Is Next Rx date <  Base date = FALSE.  After that if you see Is Next Rx date <  Base date = TRUE then Therapy = 3 and start doing Cumm. days on Therapy  and so on

I would appreciate any help in this. 

Thanks

Ksharp
Super User
data have;
input ID     RxDt : mmddyy10.     NextRxDt : mmddyy10.     DaysSupply     Daysbetweennextrefill     BasedateforPersistence : mmddyy10.;
format RxDt      NextRxDt      BasedateforPersistence  mmddyy10.;
cards;
123     1/31/2013     3/5/2013     30     33     4/1/2013
123     3/5/2013     4/3/2013     30     29     5/4/2013
123     4/3/2013     5/1/2013     30     28     6/2/2013
123     5/1/2013     6/5/2013     30     35     6/30/2013
123     6/5/2013     7/3/2013     30     28     8/4/2013
123     7/3/2013     8/2/2013     30     30     9/1/2013
123     8/2/2013     1/28/2014     30     .     10/1/2013
123     1/28/2014     2/26/2014     30     29     3/29/2014
123     2/26/2014     3/26/2014     30     28     4/27/2014
123     3/26/2014     4/25/2014     30     30     5/25/2014
123     4/25/2014     6/25/2014     30     .     6/24/2014
123     6/25/2014     7/22/2014     30     27     8/24/2014
123     7/22/2014     10/25/2014     30     .     9/20/2014
;
run;
data have;
 set have;
 length flag $ 10;
 if NextRxDt lt BasedateforPersistence then flag='TRUE';
  else flag='FALSE';
run;

data want;
 set have;
 by id flag notsorted;
 retain  Therapy ;
 if first.id then do;n=.;Therapy=.;DaysonTherapy=.;end;
 if first.flag then do; 
                     if flag='TRUE' then do;n+1;Therapy=n;end;
                           else      Therapy=.;
                         end;
 DaysonTherapy+Daysbetweennextrefill;
 if flag='FALSE' then DaysonTherapy=.;
 drop n;
run;

Xia Keshan

pp2014
Fluorite | Level 6

Thanks Xia. It worked as wanted..  One question if I have one patient on 2 drugs. So there will be another field called drug.   I want to sort them by Drug and then Patient ID and then do the # of Therapies and DaysonTherapy separately for each drug for each Patient.

How do change the logic above.

Thanks

Ksharp
Super User

I am in financial field , not in Pharmacy field . So hard to catch on you .

As my thought, if there was one more group variable DRUG :

data have;

set have;

length flag $ 10;

if NextRxDt lt BasedateforPersistence then flag='TRUE';

  else flag='FALSE';

run;

proc sort data=have; by drug id;run;

data want;

set have;

by drug id flag notsorted;

retain  Therapy ;

if first.id then do;n=.;Therapy=.;DaysonTherapy=.;end;

if first.flag then do;

                     if flag='TRUE' then do;n+1;Therapy=n;end;

                           else      Therapy=.;

                         end;

DaysonTherapy+Daysbetweennextrefill;

if flag='FALSE' then DaysonTherapy=.;

drop n;

run;

pp2014
Fluorite | Level 6

Thanks Xia. I think I can use your code by putting into a macro and use  it for the the other drugs. There  are hardly 3 more drugs.

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
  • 7 replies
  • 2322 views
  • 7 likes
  • 3 in conversation