BookmarkSubscribeRSS Feed
sarahsasuser
Quartz | Level 8

I have prescription data and am trying to look at patterns of use. I'd like to create an array that calculates the time between dates to see how often people fill their prescriptions.

 

I have up to 300 dates for each person and want to create time variables that is the number of months between prescription refills. What is the best way to do this so that I can easily see the number of months between Rx for each person (and be able to average them)? I also want to count the number of prescriptions each person has. 

 

I have wide data and though of this array:

data want;

set have;

array date(*) date1-date300;

array time(*) time1 - time299;

do i=1 to 315;    

if date(i) ^=. then do;

time(i)=ink('month', date(i),date(i+1)); *want the number of months between each date;

end;

end;

run;

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@sarahsasuser wrote:

I have prescription data and am trying to look at patterns of use. I'd like to create an array that calculates the time between dates to see how often people fill their prescriptions.

 

I have up to 300 dates for each person and want to create time variables that is the number of months between prescription refills. What is the best way to do this so that I can easily see the number of months between Rx for each person (and be able to average them)? I also want to count the number of prescriptions each person has. 

 

I have wide data and though of this array:

data want;

set have;

array date(*) date1-date300;

array time(*) time1 - time299;

do i=1 to 315;    

if date(i) ^=. then do;

time(i)=ink('month', date(i),date(i+1)); *want the number of months between each date;

end;

end;

run;

 

 


Well, other than you spelled INTCK as INK, and your array index goes 1 to 315, instead of 1 to 299, I think you have the proper code.

--
Paige Miller
sarahsasuser
Quartz | Level 8

Thanks for catching that. I fixed the code and I get an error that says the array subscript is out of range. I'm missing something...

sarahsasuser
Quartz | Level 8

ah thanks! that's what I was missing!

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
  • 5 replies
  • 1468 views
  • 0 likes
  • 3 in conversation