BookmarkSubscribeRSS Feed
_Hopper
Obsidian | Level 7

I am using the following code to create a clustered bar chart. The values are pre-summarized from MEANS using preloaded formats for a complete dataset.

 

On the X axis, Day should appear but then also an analysis category (formatted numeric value) should also appear (it does not, only Day appears). Also, no legend appears either. When I remove the keylegend line, a legend appears on the right, but it is not correct. What am I missing?

 

 

 

 

proc sgplot data=xxx;
vbar day / response = n groupdisplay = cluster stat = sum group=CATEGORY colorresponse=avalca1n colormodel = (green gold red black lightblue grey darkblue darkred)transparency=0.2 datalabel DATALABELATTRS = (size = 7pt family = "Courier New") ;
xaxis values = (0 ,30,90) labelattrs = GraphUnicodeText label = 'Day (Baseline Set to Day 0)' labelattrs = (size = 7pt family = "Courier New" ) valueattrs = (size = 7pt family = "Courier New");
yaxis values = (0 to 9 by 1) labelattrs = GraphUnicodeText label = 'n' grid labelattrs = (size = 7pt family = "Courier New" ) valueattrs = (size = 7pt family = "Courier New");
keylegend / valueattrs = GraphUnicodeText type=fillcolor title="" valueattrs = (size = 7pt family = "Courier New") sortorder = ascending;
run;

 

_Hopper_1-1717602392760.png

 

 

 

 

11 REPLIES 11
ballardw
Super User

Hard to test code or recommend changes without data.

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

 

"Preloaded formats" means that you may have to include the FORMAT code so we have that information as well.

 

You are apparently asking to have two axis variables??? How does your "analysis category" variable relate to Days? Is it supposed to be the variable you are using for Group=Category or another variable? Where is this "analysis category" supposed to appear.

 

What does "legend is not correct" mean? You don't show what you get.

 

 

Since your Xaxis and Yaxis statements have 2 Labelattrs and your Keylegend has 2 Valueattrs options I can't tell which you expected to apply (only ONE of each will be applied )

 

DanH_sas
SAS Super FREQ

There are a couple of things here:

  1. If you have pre summarized your data, it's usually better to use a VBARPARM than a VBAR.
  2. To display a COLORRESPONSE, you need to use a GRADLEGEND instead of a KEYLEGEND to show the color changes.

I think what you are trying to do is show two levels of classification on the bar chart, but COLORRESPONSE is really intended for that. I think your better option is to use PROC SGPANEL. I don't have your data to try run this, but give the code below a try and see if you get a better result.

proc sgpanel data=xxx;
panelby CATEGORY;
styleattrs datacolors=(green gold red black lightblue grey darkblue darkred);
vbarparm category=day response = n  / groupdisplay = cluster group=avalca1n transparency=0.2 
         datalabel DATALABELATTRS = (size = 7pt family = "Courier New") name="bar";
colaxis values = (0 ,30,90) labelattrs = GraphUnicodeText label = 'Day (Baseline Set to Day 0)' 
        labelattrs = (size = 7pt family = "Courier New" ) valueattrs = (size = 7pt family = "Courier New");
rowaxis values = (0 to 9 by 1) labelattrs = GraphUnicodeText label = 'n' grid 
        labelattrs = (size = 7pt family = "Courier New" ) valueattrs = (size = 7pt family = "Courier New");
keylegend "bar" / valueattrs = GraphUnicodeText type=fillcolor title="" 
        valueattrs = (size = 7pt family = "Courier New") sortorder = ascending;
run;

 

_Hopper
Obsidian | Level 7

This helps but how do you get unicode values to display properly? Which options should be added?

DanH_sas
SAS Super FREQ

Which Unicode characters?

_Hopper
Obsidian | Level 7
Less than or equal to, greater than or equal to
DanH_sas
SAS Super FREQ

Where are you putting these characters? Your category axis is "Day". As @ballardw pointed out, you have conflicting LABELATTRS specifications on your axes. By overriding the FAMILY, you are removing the main reason for using the GraphUnicodeText style element reference, as the font family in that style element is a full-featured Unicode font. However, I don't see any Unicode characters in your axis LABELs, so I'm not sure if you intend to put them in the axis label or the axis tick values.

_Hopper
Obsidian | Level 7
They are in the PANELBY variable in your example.
I'll remove those other items from the axes.
_Hopper
Obsidian | Level 7

This is how I want the chart to look - isn't there a simpler approach to doing it that will also handle the unicode values?

 

_Hopper_0-1717612671206.png

 

_Hopper
Obsidian | Level 7

The last version of recommended code renders like this:

 

_Hopper_0-1717613006763.png

 

DanH_sas
SAS Super FREQ

To put the characters in the headers, you will need to use a user-defined format associated with your CATEGORY variable. here is a simple example:

proc format;
value $gender "F"="Female (*ESC*){unicode '2640'x}"
              "M"="Male (*ESC*){unicode '2642'x}"
;
run;

proc sgpanel data=sashelp.class;
format sex $gender.;
panelby sex / novarname headerattrs=(family="Arial Unicode MS");
vbar age / response=weight stat=mean;
run;

The (*ESC*) is an ODS escape character sequence needed to have the "unicode" function interpreted. You can have as many of these in the string as you want, in any order. In the HEADERATTRS, I specified a font that I knew would contain the characters I needed. the GraphUnicodeText reference would work for you as well. You can still override attribute of that style element is you want (e.g. headerattrs=GraphUnicodeText(size=11pt)). The Unicode value for "less than or equal to" is '2264'x.

 

I just saw the picture you send. If you want all of the cells to be in one row, you might want to add LAYOUT=COLUMNLATTICE to the PANELBY statement. Also try the NOVARNAME option, if our CATEGORY value are self-explanatory.

 

Let me know if you have any questions about this.

DanH_sas
SAS Super FREQ

If you use LAYOUT=COLUMNLATTICE, you can also use the NOBORDER option on the PANELBY statement to get rid of the lines between the cells, NOHEADERBORDER to get rid of the border around the headers, and move the headers below the bottom axis using COLHEADERPOS=BOTTOM.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 2076 views
  • 0 likes
  • 3 in conversation