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

Hi I need some helps with sgplot.

I wish to build a couple of stacked bar chart with the code samples as below 

 

proc sgplot data=mydata noborder pctlevel=group;
 by Label notsorted;
 styleattrs datacolors=(bigb  bibg bio brown yellow red) ;
  vbar Day/group=Grade stat= pct groupdisplay=stack fill grouporder=ascending missing;
  xaxis integer values=(1 2 3 4 5 6 7);
run;

At first, I want to make a 100% stacked bar chart (including missing value) on each Day. My data has 5 grade: 0,1,2,3,4 and missing data (display as "." bcs Grade is numeric variable)

 

And now I encounter 2 problems:

- How can I retain the percentage of other values on the bar on each day if I don't want the percentages of missing value and grade 0 to be displayed on my chart ?

- How can I fix the color code with each value eg I want missing value to be display with bigb color (as the order shown in datacolors= syntax)

Thanks in advance.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Pre process your data so it’s summarized ahead of time. You can control your colours with items by using a data attribute map.

A rough idea how to get the graph started can be found in this post which does a stacked bar chart in the first set of code I posted.
https://communities.sas.com/t5/SAS-Programming/GROTTA-BAR/m-p/762632

Examples of data attribute map.

https://documentation.sas.com/doc/en/vdmmlcdc/8.11/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm#!

View solution in original post

2 REPLIES 2
Reeza
Super User
Pre process your data so it’s summarized ahead of time. You can control your colours with items by using a data attribute map.

A rough idea how to get the graph started can be found in this post which does a stacked bar chart in the first set of code I posted.
https://communities.sas.com/t5/SAS-Programming/GROTTA-BAR/m-p/762632

Examples of data attribute map.

https://documentation.sas.com/doc/en/vdmmlcdc/8.11/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm#!

James_Yu
Obsidian | Level 7
Thanks alot.
This helps me to complete my code

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 1138 views
  • 0 likes
  • 2 in conversation