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

Hello Community,

 

I have a data analysis problem that I was wondering if I could get some help with. I am analyzing some healthcare data, which includes the dates that a certain medication was prescribed (Date), the number of days of each prescription since the initial prescription for each patient (Days), and the number of days between subsequent prescriptions (Days_bwn).

 

I need to calculate the average number of days between prescriptions received within 180 days of the first prescription (Days le 180). HOWEVER, for patients who only had ONE prescription within 180 days, the first prescription received after 180 days of the first prescription will be used to calculate the average time between prescriptions (see patient_ID 3 for example). Could someone please help me with the code to produce the desired output as shown below? Please let me know if I can provide any clarification or additional information. Thank you!!

 

Have:

Patient_ID

Date

Days

Days_bwn

1

15DEC2019

0

.

1

30JAN2020

46

46

1

01MAR2020

77

31

1

15APR2020

122

45

2

26DEC2019

0

.

2

10JAN2020

15

15

2

03MAR2020

68

53

2

18MAY2020

144

76

2

26JUN2020

183

39

2

18JUL2020

205

22

3

30AUG2017

0

.

3

29MAY2018

272

272

3

07JUN2018

281

9

 

Want:

Patient_ID

Mean

1

40.667

2

48

3

272

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

This does not deal with the case of having multiple prescriptions on the same day - not sure how you'd want to account for that. 

 

data inclusion;
set have;
by patient_id date;
if first.patient_id then counter=0;
counter+1;
if counter<=2  then inclusion=1;
else if days <180 then inclusion=1;
run;

proc means data=inclusion;
where inclusion=1;
class patient_id;
var Days_bwn;
run;

View solution in original post

1 REPLY 1
Reeza
Super User

This does not deal with the case of having multiple prescriptions on the same day - not sure how you'd want to account for that. 

 

data inclusion;
set have;
by patient_id date;
if first.patient_id then counter=0;
counter+1;
if counter<=2  then inclusion=1;
else if days <180 then inclusion=1;
run;

proc means data=inclusion;
where inclusion=1;
class patient_id;
var Days_bwn;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 838 views
  • 1 like
  • 2 in conversation