BookmarkSubscribeRSS Feed
Fluorite | Level 6

I have a number of different bar charts that are going into the same presentation.  SAS (9.4) is arbitrarily (at least that's how I view it) assigning colors to the segments of the bars and they are not consistent across charts.  I would like to assign the colors.   In addition, I cannot figure out how to put a border around the whole chart.


I have attached sample data...I have many more managers and observations than what is in the sample.  I've also attached a snippet of the resulting chart.


Legend1 label=none ;
ods graphics / border=on ;
goptions border ;

Proc GCHART data=MgrName ;
vbar Usage_Month / discrete subgroup=Manager legend=legend1 type = freq ;
Run ;




Super User

Gchart generally assigns appearance based on the order of appearance of a value in the data matched against the current list of PATTERN statements in effect. The "randomness" may be reduced by sorting the data by that variable so the values appear in order more often.

As such, keeping colors/ patterns/symbols consistent for "Fred", especially when "Fred" does not appear in every graph is extremely challenging.


You might want to consider moving to Proc SGPLOT / SGPANEL. The later versions of SAS include the statistical graph procedures as part of the base SAS installation. The feature you are looking for involves DATTRMAP data sets where you can create a data set that supplies one or more sets of rules so that "Fred" will always have the same color, pattern, marker symbol, line pattern or other graphics appearance option.

This really is not a short 3 or 3 line to describe and us though. Look in the documentation for Proc SGPLOT statement and the option DATTRMAP. SGPANEL is similar but allows showing graphs with a separate graph for each combination of one or more other variables.


Here is a simple example:


data attrmap;
retain id "myid" linecolor "black";
input value $ fillcolor $;
F pink
M blue

proc sgplot data=sashelp.class dattrmap=attrmap;
vbar age / response=weight stat=mean group=sex
           attrid=myid groupdisplay=cluster;



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3 in conversation