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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1451 views
  • 0 likes
  • 2 in conversation