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;
@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.
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...
ah thanks! that's what I was missing!
Transpose your dataset, use lag() to determine the difference between observations, and then proc means/summary for the calculation.
See Maxim 49.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.