BookmarkSubscribeRSS Feed
Calcite | Level 5

Hello, I've created a report that runs data for ~50 different entities and generates tables/graphs for each into its own pdf that's then being emailed via SAS.  One type of graph has given me problems:

I've created a table - let's say overall performance - that has every entity and a score from 0-100 in it. This is plotted into a bar chart in ascending order. What I'd like to do is highlight one bar in the chart each time it's generated so that each entity can quickly approximate where their performance lies in relation to their peers (see attached).

Any ideas? It's appreciated. I've been trying various things and searching for days but overlay/highlight are too broad of terms to find my answer. I'm an advanced user running SAS 9.2.

Meteorite | Level 14

I must be missing something, as I would think you could use the GROUP option to highlight the one bar you want.

Super User

Some code how you are generating the charts might help to address specific options

The general approach is to assign a categorical variable that is assigned one value for your entity and another value for all others. The syntax to get the color change will change depending on the proc used. You will likely also want to suppress the default legend unless you find it helpful.

Meteorite | Level 14

Here is one way to do it with gchart ...

data my_data; set sashelp.class;

if name='Alfred' then hilight='Y';

else hilight='N';


axis1 label=none value=(angle=90);

axis2 label=none;

pattern1 v=solid c=blue;

pattern2 v=solid c=red;

proc gchart data=my_data;

vbar name / type=sum sumvar=weight descending

subgroup=hilight nolegend maxis=axis1 raxis=axis2;


Calcite | Level 5

Right, so you (the original poster) might want to make use of a macro variable in the data step to dynamically change the value that gets used to flag the highlight column.

Presumeably, you are already doing some kind of macro to loop through your 50+ entities.

For example:

Say you are looping through store names, and have a macro variable called ThisStore for the current store name.

Data my_data ;

  set StoreSales ;

  if storeName = "&ThisStore" then hilight='Y' ;

  else hilight='N' ;

run ;

(Note the use of double-quotes when using a macro variable to substitute in a character variable value.)

Meteorite | Level 14

Excellent addition, cwilson!

Calcite | Level 5

Thanks for the help folks! Since this is 2012 I'm using proc template and sgrender to create my graphs rather than gchart but the same ideas apply =P. I never even considered creating another field to do the graph as I was convinced there was a more elegant approach. I ended up creating a new field for highlighting like this

data temp;

set original;

if entity=&macroentity then hilight=performance;

else hilight=0;

And then overlaid that on top of the full chart containing every entity (using barchart command in proc template). It has to recreate the table every iteration - not ideal - but it works fine with some sleep pauses and gives me something else to point to when lobbying for an improved machine =). Thanks again

Meteorite | Level 14

Gchart still works in 2012 ... better than ever, actually! 🙂



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
  • 7 replies
  • 5 in conversation