BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_student1
Quartz | Level 8

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

 

 


 

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

 

 


 

sas_student1
Quartz | Level 8

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;

 

Reeza
Super User
You can add the NWAY option to your first PROC MEANS statement and it will only calculate the 'highest' level of the class variable.
sas_student1
Quartz | Level 8

excellent! Thank You!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1406 views
  • 0 likes
  • 2 in conversation