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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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