BookmarkSubscribeRSS Feed
f_rederik
Obsidian | Level 7

Hi all

I am building a report for a client using PROC GCHART to display a 'stacked bar chart' showing the volume of product sales across a number of different branches (plus also the total for all branches).

Below each bar chart I will display a table of the relevant data. To achieve this, I've built two macros, one for the bar chart (PROC GCHART) and another one for the table (PROC TABULATE), both accepting the branch as an input parameter. I then run these macros for the individual branches and also for the total of all branches.

This works nicely, but I have one challenge when it comes to the visuals. Not all branches have all products, leading to the use of colours (in the PATTERN statement) being inconsistent across the branches. For example, for branch A, 'mortgages' will be in a yellow bar, whereas for branch B (that does not have mortgages), the yellow color now represents credit cards.

Using Google I found a SAS Note with an example that I have tried to modify (41603 - Reorder the subgroups in stacked bars using PROC GCHART) however this proves too difficult as my coding skills aren't up to the task.

To summarise I think I have two questions;

1) I assume that using the same PROC GCHART and a 'GROUP BY' will achieve color consistency, but how can i then elegantly display the PROC TABULATE or similar table showing the actual data below each graph? (some of the product categories have small volumes, hence labelling the graph is not very user friendly)

2) If (1) is difficult or impossible, any other options to ensure consistency between colors for the same value of SUBGROUP in the different runs of the PROC GCHART?

Thanks for any assistance or pointers Smiley Wink

Fred

3 REPLIES 3
DanH_sas
SAS Super FREQ

What version of SAS are you using?

f_rederik
Obsidian | Level 7

PROC PRODUCT STATUS says 9.21_M2 for SAS/GRAPH and 9.21_M3 for 'Base Product' if that makes sense?

DanH_sas
SAS Super FREQ

Assuming you have SAS 9.3 or greater, I would recommend using PROC SGPLOT with an attributes map to associate the bar fill colors directly with the group values. Note that the values in the attrmap data set are case-sensitive:

data attrmap;

retain id "gender";

input value $ fillcolor $;

cards;

F pink

M blue

;

run;

Title "Total Weight by Age";

proc sgplot data=sashelp.class dattrmap=attrmap;

vbar age / response=weight group=sex attrid=gender nooutline;

run;

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