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

Both can be used but I like the second plots. So they are both great solutions.

desireatem
Pyrite | Level 9

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"

 

 

 

desireatem_0-1629303961596.png

 

Reeza
Super User

Show your full code with sample data. Obviously that isn't my code otherwise the categories would be as shown in the FORMAT statement.

desireatem
Pyrite | Level 9

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;

Reeza
Super User
Yeah, doesn't seem like it's quite right. Can you please clarify the requirements based on the sample data I provided. Exactly what numbers do you expect to see in the bars based on that random data.
desireatem
Pyrite | Level 9

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

Reeza
Super User

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; 
desireatem
Pyrite | Level 9

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"

 

 

 

desireatem_0-1629318115466.png

 

Reeza
Super User
Is the data represented correctly such that I make those changes it would be what you need? I don't think that's right because if the bars are filled at 100% then that's a stacked bar chart, which this is not. It shows percent of total not row percent.

Which was the difference between the original two graphics created and my original question of which answer was right.....

desireatem
Pyrite | Level 9

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"???

 

 

desireatem_0-1629322037554.png

 

Reeza
Super User
LABEL.
desireatem
Pyrite | Level 9

Sorry Reeza, I do not understand. 

desireatem
Pyrite | Level 9

Thank you, this complete it.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 28 replies
  • 3324 views
  • 6 likes
  • 3 in conversation