Hi,
I have a question related to calculate time span between the first and last date within 2 variables group. My data looks like below, sorted by student_id test_id date. I need count time span between the first and last date for each test_id of each student_id. Thanks much in advance for your help!
My data:
student_id | test_id | date |
aaa | 123 | 05/06/2012 |
aaa | 123 | 06/07/2012 |
aaa | 123 | 02/06/2013 |
aaa | 345 | 12/17/2012 |
aaa | 345 | 07/22/2013 |
aaa | 345 | 11/11/2013 |
bbb | 234 | 02/29/2012 |
bbb | 234 | 05/30/2012 |
bbb | 789 | 07/19/2013 |
bbb | 789 | 07/31/2013 |
bbb | 789 |
09/30/2013 |
What I want is:
student_id |
test_id |
time_span |
aaa |
123 |
276 |
aaa |
345 |
329 |
bbb |
234 |
91 |
bbb |
789 |
73 |
Try this:
proc summary data=have nway;
class student_id test_id;
var date;
output out=want(drop=_:) range(date)=time_span;
format date best6.;
run;
Please fix your data.
Try this:
proc summary data=have nway;
class student_id test_id;
var date;
output out=want(drop=_:) range(date)=time_span;
format date best6.;
run;
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.