Data visualization with SAS programming

PROC GCHART - create multiple graphs with the same color for SUBGROUP

Reply
Contributor
Posts: 32

PROC GCHART - create multiple graphs with the same color for SUBGROUP

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

SAS Super FREQ
Posts: 925

Re: PROC GCHART - create multiple graphs with the same color for SUBGROUP

What version of SAS are you using?

Contributor
Posts: 32

Re: PROC GCHART - create multiple graphs with the same color for SUBGROUP

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

SAS Super FREQ
Posts: 925

Re: PROC GCHART - create multiple graphs with the same color for SUBGROUP

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;

Ask a Question
Discussion stats
  • 3 replies
  • 501 views
  • 0 likes
  • 2 in conversation