11-24-2014 05:08 AM
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
11-24-2014 08:33 AM
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:
retain id "gender";
input value $ fillcolor $;
Title "Total Weight by Age";
proc sgplot data=sashelp.class dattrmap=attrmap;
vbar age / response=weight group=sex attrid=gender nooutline;