Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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