Both can be used but I like the second plots. So they are both great solutions.
Hello Reeza. I marked this as correct but for some reason the colors in the grotta bar does not match the key below. For home and IRF both should have same color for 0, 1, 2...., 6. Also how do I change the name form mrs_discharge in the key to "mrs at discharge"
Show your full code with sample data. Obviously that isn't my code otherwise the categories would be as shown in the FORMAT statement.
proc format;
value mRS_fmt
0 = "mRS 0"
1 = "mRS 1"
2 = "mRS 2"
3 = "mRS 3"
4 = "mRS 4"
5 = "mRS 5"
6 = "mRS 6";
run;
proc format;
value disposition_fmt
0 = "Home"
3 = "IRF";
run;
proc freq data=IRF_sub;
table disposition_1*mrs_discharge/ out=summary_data outpct;
format mrs_discharge mRS_fmt.;
run;
title "Discharge mRS by Disposition";
proc sgplot data=summary_data;
hbar disposition_1 / group = mrs_discharge response = pct_row stat=pct;
*to get counts labelled;
hbar disposition_1 / group = mrs_discharge response = count stat=sum seglabel x2axis;
x2axis display=none;
format disposition_1 disposition_fmt.;
run;
There are two gropus "Home Discharge" and "IRF Discharge" see table below. For for mRS at discharge equal 0, there were 75 from home discharge and 2 from IRF, so both should have same color . The proportion of the color in both group should be it proportion by group, that is 75/(75+176+ 106 +84+38+11+6) for home discharge and 2/(2+32+36+59+86+16+8). Similar computation should be done for each mRS discharge by group
mRS at Hospital Discharge |
Home Discharge |
IRF Discharge |
0 |
75 |
2 |
1 |
176 |
32 |
2 |
106 |
36 |
3 |
84 |
59 |
4 |
38 |
86 |
5 |
11 |
16 |
6 |
6 |
8 |
If that was your data set does this graph show properly then?
proc transpose data=have out=tall;
by mrs;
var home irf;
run;
proc sgplot data=tall;
hbar _name_ / response = col1 group = mrs stat=pct;
run;
This is is an improvement but there are few issue.
1) The number for each color is not presented
2) The x-axis should be from 0 to 100%, since we are dealing with row percent.
3) I wish to change mrs_discharge on the key to "mRS at discharge"
Thank you. I took off the percent in the x-axis and that's fine but how can I change the name in the key from "mrs_discharge" to "mRS at Discharge"???
Sorry Reeza, I do not understand.
Thank you, this complete it.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.