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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1721 views
  • 0 likes
  • 3 in conversation