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

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;

 

palolix_0-1747260701469.png

Frequency
Percent
Row Pct
Col Pct
Table of Variety by PeelColor
Variety PeelColor
3 4 Total
Hass
2
5.00
5.00
100.00
38
95.00
95.00
100.00
40
100.00
 
 
Total
2
5.00
38
95.00
40
100.00

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1747284784021.png

 

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

 

palolix
Pyrite | Level 9

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;

palolix_0-1747274690287.png

The percentages labeled are total percentages from all seasons.

Ksharp
Super User

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;

Ksharp_0-1747284784021.png

 

palolix
Pyrite | Level 9

Thank you so much Ksharp, thats exactly what I wanted!

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
  • 1247 views
  • 4 likes
  • 3 in conversation