Hi! I need help calculating the number of actual days a person was in my 5 year study. So, looking accross observations, I need to calculate number of days between the first encounter date 'encdate' and last encounter date by 'patientid'.
Assistance is apprecited!
Here's one approach.
proc summary data=have nway;
class patientid;
var encdate;
output out=durations (keep=patientid firstday lastday) min=firstday max=lastday;
run;
This gives you a data set with three variables in it, and one observation per patientid. You can use that in a DATA step, and apply whichever formula you wish:
duration = lastday - firstday;
duration = lastday - firstday + 1;
The SQL programmers out there can do this in one step, but SQL isn't my strong point.
Please post sample input and output data.
Here's one approach.
proc summary data=have nway;
class patientid;
var encdate;
output out=durations (keep=patientid firstday lastday) min=firstday max=lastday;
run;
This gives you a data set with three variables in it, and one observation per patientid. You can use that in a DATA step, and apply whichever formula you wish:
duration = lastday - firstday;
duration = lastday - firstday + 1;
The SQL programmers out there can do this in one step, but SQL isn't my strong point.
Minor change to @Astounding solution:
output out=durations (keep=patientid firstday lastday) range=;
Range will basically do the max-min.
how can i get sas software
1. Please post your questions in a new discussion rather than in someone else's question
2. Google "SAS University Edition" -> This is a free version of SAS available for learning purposes only. You need a 64bit machine.
Or use SAS Academics on Demand -> Independent Learners option.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.