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

Hi all,

I have a categorical variable in my data. I am trying to draw a bar graph for this variable based on the percents. The below code is working but the sum of percentages is not 100%. I don't know how it is calculating this. Is there an easy way to draw a percentage-based bar graph?

 

Thank you,

 

proc sgplot data=alt_listening;
title "Proficiency Level: List 1-2";
vbar listening_pl / stat=pct transparency=0.25 fillattrs=(color=black) ;
yaxis label= 'Percent' ;
xaxis label= 'Proficiency Level';
by cluster_listening;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
dustychair
Pyrite | Level 9
Thank you for your response. I think I got it. I modified my code as below and it worked.

proc sgplot data=alt_listening PCTLEVEL=BY;
title "Proficiency Level: List 1-2";
vbar listening_pl / stat=pct transparency=0.25 fillattrs=(color=black) ;
yaxis label= 'Percent' ;
xaxis label= 'Proficiency Level';
by cluster_listening;
run;

Thank you again

View solution in original post

3 REPLIES 3
djrisks
Barite | Level 11
Hello,
Please can you also include your data or an example of your data?
dustychair
Pyrite | Level 9
Thank you for your response. I think I got it. I modified my code as below and it worked.

proc sgplot data=alt_listening PCTLEVEL=BY;
title "Proficiency Level: List 1-2";
vbar listening_pl / stat=pct transparency=0.25 fillattrs=(color=black) ;
yaxis label= 'Percent' ;
xaxis label= 'Proficiency Level';
by cluster_listening;
run;

Thank you again
DanH_sas
SAS Super FREQ

For the record, the default percentage basis is the entire graph output, including all BY-groups. To change this basis, use the PCTLEVEL option like you did set the level you want to be the basis for 100%. In SGPLOT, there are three levels: Graph (the default), BY (for BY-groups), and Group (all groups within a category = 100%). For SGPANEL, there are four levels: Graph, BY, Cell (all bars in each cell = 100%), and Group.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 3 replies
  • 1099 views
  • 5 likes
  • 3 in conversation