Hello,
I have data that resembles the below, and need to calculate the average time (in months) between dates in the Event_date column, grouped by Subject_ID. In other words, for each subject in the data, I need to know the average number of months between events relevant to that subject. Each subject has a different number of events that are associated with them. Is there a relatively straightforward way to do this? I know how to do this in R, but I'm relatively new to SAS and haven't been able to figure out a solution just yet.
Thanks in advance for any help this community can provide!
Subject_ID | Event_date |
1 | Date_1 |
1 | Date_2 |
1 | Date_3 |
2 | Date_1 |
2 | Date_2 |
3 | Date_1 |
3 | Date_2 |
3 | Date_3 |
3 | Date_4 |
3 | Date_5 |
3 | Date_6 |
4 | Date_1 |
4 | Date_2 |
5 | Date_1 |
5 | Date_2 |
5 | Date_3 |
5 | Date_4 |
6 | Date_1 |
6 | Date_2 |
What do you mean by "the average number of months between events"?
Can you post some real data and the desired output you are looking for ?
data have;
input id date date9.;
format date date9.;
cards;
1 01jan2010
1 01mar2011
1 01feb2012
2 01nov2010
2 01mar2011
2 01dec2014
;
proc sort data=have out=temp;
by id date;
run;
data temp;
set temp;
by id;
n_month=intck('month',lag(date),date,'c');
if first.id then call missing(n_month);
run;
proc summary data=temp;
by id;
var n_month;
output out=want mean=;
run;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.