Hello!
I have a dataset where I have flagged hospital visits in to episodes (actually this article helped me a lot into making the episodes: https://support.sas.com/resources/papers/proceedings15/3281-2015.pdf)
Now the issue I am having is that I want to get statistics, such as average, min, max, median etc. on the max eoh (i.e hospital episode).
In the dataset below patients 001 and 003 had a max of 3 episodes, patients 002, 004 and 005 had 1 hospital episode each. So the average of the 5 patients would be 1.8 episodes (3+3+1+1+1 / 5)
I having a feeling the solution is simple, like running a proc means etc. but I am getting stuck and cant figure out how to calculate the statistics.
Any suggestion would be helpful!
data testhosp1;
informat patient_id $3. adm_date mmddyy10. dschg_date mmddyy10. eoh 1.;
input patient_id adm_date dschg_date eoh;
format adm_date dschg_date mmddyy10.;
datalines;
001 04/01/2014 04/04/2014 1
001 04/02/2014 04/02/2014 1
001 04/04/2014 04/06/2014 1
001 04/07/2014 04/09/2014 1
001 09/01/2014 09/05/2014 2
001 12/01/2014 12/03/2014 3
001 12/03/2014 12/03/2014 3
001 12/03/2014 12/06/2014 3
002 04/01/2014 04/04/2014 1
003 04/02/2014 04/02/2014 1
003 04/04/2014 04/06/2014 2
003 04/07/2014 04/09/2014 2
003 09/01/2014 09/05/2014 3
004 12/01/2014 12/03/2014 1
004 12/03/2014 12/03/2014 1
005 12/03/2014 12/06/2014 1
;
run;
Yes, but you need a double proc means.
1. Do a proc means to get the max per each ID
2. Do a proc means off the results from #1.
Do you know how to run a proc means?
@sas_student1 wrote:
Hello!
I have a dataset where I have flagged hospital visits in to episodes (actually this article helped me a lot into making the episodes: https://support.sas.com/resources/papers/proceedings15/3281-2015.pdf)
Now the issue I am having is that I want to get statistics, such as average, min, max, median etc. on the max eoh (i.e hospital episode).
In the dataset below patients 001 and 003 had a max of 3 episodes, patients 002, 004 and 005 had 1 hospital episode each. So the average of the 5 patients would be 1.8 episodes (3+3+1+1+1 / 5)
I having a feeling the solution is simple, like running a proc means etc. but I am not getting stuck and cant figure out how to calculate the statistics.
Any suggestion would be helpful!
data testhosp1; informat patient_id $3. adm_date mmddyy10. dschg_date mmddyy10. eoh 1.; input patient_id adm_date dschg_date eoh; format adm_date dschg_date mmddyy10.; datalines; 001 04/01/2014 04/04/2014 1 001 04/02/2014 04/02/2014 1 001 04/04/2014 04/06/2014 1 001 04/07/2014 04/09/2014 1 001 09/01/2014 09/05/2014 2 001 12/01/2014 12/03/2014 3 001 12/03/2014 12/03/2014 3 001 12/03/2014 12/06/2014 3 002 04/01/2014 04/04/2014 1 003 04/02/2014 04/02/2014 1 003 04/04/2014 04/06/2014 2 003 04/07/2014 04/09/2014 2 003 09/01/2014 09/05/2014 3 004 12/01/2014 12/03/2014 1 004 12/03/2014 12/03/2014 1 005 12/03/2014 12/06/2014 1 ; run;
Yes, but you need a double proc means.
1. Do a proc means to get the max per each ID
2. Do a proc means off the results from #1.
Do you know how to run a proc means?
@sas_student1 wrote:
Hello!
I have a dataset where I have flagged hospital visits in to episodes (actually this article helped me a lot into making the episodes: https://support.sas.com/resources/papers/proceedings15/3281-2015.pdf)
Now the issue I am having is that I want to get statistics, such as average, min, max, median etc. on the max eoh (i.e hospital episode).
In the dataset below patients 001 and 003 had a max of 3 episodes, patients 002, 004 and 005 had 1 hospital episode each. So the average of the 5 patients would be 1.8 episodes (3+3+1+1+1 / 5)
I having a feeling the solution is simple, like running a proc means etc. but I am not getting stuck and cant figure out how to calculate the statistics.
Any suggestion would be helpful!
data testhosp1; informat patient_id $3. adm_date mmddyy10. dschg_date mmddyy10. eoh 1.; input patient_id adm_date dschg_date eoh; format adm_date dschg_date mmddyy10.; datalines; 001 04/01/2014 04/04/2014 1 001 04/02/2014 04/02/2014 1 001 04/04/2014 04/06/2014 1 001 04/07/2014 04/09/2014 1 001 09/01/2014 09/05/2014 2 001 12/01/2014 12/03/2014 3 001 12/03/2014 12/03/2014 3 001 12/03/2014 12/06/2014 3 002 04/01/2014 04/04/2014 1 003 04/02/2014 04/02/2014 1 003 04/04/2014 04/06/2014 2 003 04/07/2014 04/09/2014 2 003 09/01/2014 09/05/2014 3 004 12/01/2014 12/03/2014 1 004 12/03/2014 12/03/2014 1 005 12/03/2014 12/06/2014 1 ; run;
Ah! I knew it was going to be an obvious answer!!
Yes, so I run the below and it worked.
I could not figure out how not to output the _type_ =0 into the database called "new" , so I just made a where statement in the my second proc means.
Unless you know how to not get the _type_=0 in the original database?
proc means data=finaldatast ;
class patient_id;
var eoh;
output out=new mean= median= max= / autoname;
run;
proc means data=new ;
var eoh_max;
where _type_ ne 0;
run;
excellent! Thank You!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.