Data visualization with SAS programming

Highlighting one value in a bar graph

New Contributor
Posts: 3

Highlighting one value in a bar graph

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.

Posts: 1,086

Re: Highlighting one value in a bar graph

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

Grand Advisor
Posts: 10,262

Re: Highlighting one value in a bar graph

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.

SAS Employee
Posts: 967

Re: Highlighting one value in a bar graph

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;


Posts: 43

Re: Highlighting one value in a bar graph

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.)

SAS Employee
Posts: 967

Re: Highlighting one value in a bar graph

Excellent addition, cwilson!

New Contributor
Posts: 3

Re: Highlighting one value in a bar graph

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

SAS Employee
Posts: 967

Re: Highlighting one value in a bar graph

Gchart still works in 2012 ... better than ever, actually! :-)

Ask a Question
Discussion stats
  • 7 replies
  • 5 in conversation