BookmarkSubscribeRSS Feed
ABritinAus
Obsidian | Level 7

Greetings from Australia.

I produced the following grouped bar chart using SGPLOT.

Not convinced its the best way to present such data but I just do as I'm told 🙂

   vbar.PNG

It needs some stylising which I can easily do.

However, where I work has very strict style requirements.  One being that if the bars in the chart have no outline, then the "bars" in the legend must also have no outline.  (and for coloured bars, no outline is the requirement).

The SGPLOT code I used was

sgplot data=fig_ageSpeo_rates /*noautolegend*/;


vbar age_group/response=value group=qty_sex groupdisplay=cluster barwidth=1 nooutline;


yaxis min=0 max=5000 offsetmax=0 label='Rate';


xaxis label='Age';


keylegend/noborder position=top across=4 location=outside;

;

Does anyone know an easy way to get the legend 'squares' to not have an outline? (like you would get with SAS\Graph).

I did something with GTL and LEGENDITEMS but that seems way too complicated for most of our users here to have to grapple with.

All advice appreciated.  Am using SAS9.3 on a windows server.  I do also have access to SAS 9.4.

9 REPLIES 9
DanH_sas
SAS Super FREQ

You can work around this behavior by making the outline color to be the same as the background instead of using NOOUTLINE. Try specifying OUTLINEATTRS=(color=white) and see if you get what you want.

Hope it helps!

Dan

ABritinAus
Obsidian | Level 7

Thanks Dan.

That works nicely on 9.4.  outlineattrs seems to only be in 9.4 though?  Some of users are still on 9.3 (a long story).

I'm guessing there's no 9.3 workaround?

Simon

Jay54
Meteorite | Level 14

There are two ways. 

1.  Derive a new style from the one you like and set the GraphOutlines contrastcolor to the same as the GraphWalls color.

2.  From SGPLOT, write out the GTL code using TMPLOUT='filename.sas'.  In the GTL code, in the BARCHARTPARM statement, set the OutlineAttrs=(color=GraphWalls:contrastcolor), just like you did in SG.

ABritinAus
Obsidian | Level 7

Thanks for the prompt reply late in your day Sanjay. Much appreciated.

I tried option1 but it didn't seem to do anything.  Could you specify the exact syntax for me please?

Option2 works but then with the white outline it now looks like there is a space between the grouped bars, which is not what we want.

Using the outlineattrs option Dan mentioned (in 9.4), did not introduce the 'space' issue though.

Jay54
Meteorite | Level 14

In GTL, set the option DISPLAY=(FILL) for the bar chart.

Jay54
Meteorite | Level 14

We dug deeper to review what was happening.  Here is the scoop:

With SAS 9.4, the legend color swatch outlines use the OutlineAttrs.  SGPLOT also supports OutlineAttrs option, so you can use the following code to get the results you want.  Swatches can be made bigger by setting AutoItemSize AND increasing the legend value font size. No change to a style is needed.

proc sgplot data=sashelp.cars;

  vbar origin / group=type response=mpg_city stat=mean groupdisplay=cluster outlineattrs=(thickness=0 color=white);

  keylegend / autoitemsize valueattrs=(size=12);

  run;

outlines35.png

We discovered that at SAS 9.3, swatch outlines are determined internally.  A work around is possible for a special case that has only bar charts in the graph.    

ABritinAus
Obsidian | Level 7

Thanks (again) for following up Sanjay.

Is the workaround for 9.3 the one you have already mentioned (in no.3 of this discussion) or something else?

If its the workaround in no.3   are you able to provide the exact syntact for point 1 of that post?

Thanks.

ABritinAus
Obsidian | Level 7

I tried (in SAS9.3) outlineattrs=(color=white thickness=0) in GTL but it still drew a white "outline" and hence there was a small gap between bars (and the legend squares looked a bit small).  I verified this by changing the color to red. The outline appeared.  It seems that (in 9.3) for the outlineattrs in GTL thickness of 0 is in fact the same as 1. 

Jay54
Meteorite | Level 14

The work around needed to overcome the built in logic is more complicated and will only work if you have a graph that has only a Bar Chart, without combining with other plot types.  It is kind of ugly, so I hesitate to even go there unless this is necessary, and it fits the above restriction.  Is removing the legend swatch outline really important?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 5501 views
  • 6 likes
  • 3 in conversation