Dear SAS Community,
I was hoping to label each category in the bars with the respective percentage, but instead I am getting these numbers. According to the freq table, for the season=2024 the percentage for Hass should be 95% for PeelColor=4 so I wonder what '152' means (green color last column on the right). I would greatly appreciate your help!
This is the code I am using :
title "100 Stacked Bar Chart Ordered by Percentages";
proc sgpanel data=one ;
where Variety in('BL516', 'Hass');
panelby Season / columns=4 one panel;
vbar Variety / response=PeelColor group=PeelColor
grouporder=data groupdisplay=stack seglabel ;
colaxis discreteorder=data;
rowaxis grid values=(0 to 100 by 10) label="Percentage of PeelColor category";
run;
|
|
Ha. You need another option PCTLEVEL= too.
proc sgpanel data=sashelp.heart pctlevel=group; panelby status / columns=2 onepanel; vbar bp_status / response=weight group=sex grouporder=data groupdisplay=stack seglabel stat=percent ; colaxis discreteorder=data; run;
What is 4*38? 152.
Look at the STAT= option of VBAR. It is SUMming the values of Peelcolor value by default.
Try STAT=PERCENT.
HINT: Almost all the categorization plots are going to default to a FREQ (count) or SUM of sort.
Oh that's right, thank you very much for the clarification.
I tried this code including stat=percent and I think this graph makes more sense to me:
proc sgpanel data=one ;
where Variety in('BL516','Hass');
panelby Season / columns=4 onepanel;
vbar Variety / group=PeelColor stat=percent
groupdisplay=stack seglabel /*seglabelattrs=(size=12 color=white)*/;
run;
The percentages labeled are total percentages from all seasons.
Ha. You need another option PCTLEVEL= too.
proc sgpanel data=sashelp.heart pctlevel=group; panelby status / columns=2 onepanel; vbar bp_status / response=weight group=sex grouporder=data groupdisplay=stack seglabel stat=percent ; colaxis discreteorder=data; run;
Thank you so much Ksharp, thats exactly what I wanted!
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.