BookmarkSubscribeRSS Feed
Obsidian | Level 7

I've got code in place for a panel plot where everything is working as i wish, however i would like to have a y-axis label that is too long for the size of the graph.  I'd like to be able to 'wrap' the label down to a second line, and i thought i could accomplish this via escapechar, but this doesn't seem to be working.  Is it not possible to use escapechar in this manner to create a new line?

ods listing close;

ods escapechar="^";

ods listing style=styles.diss_style;

ods graphics/reset imagename="figure1" border=off /*height= width=8.0 in*/ scale=on ;

proc sgpanel data=n1_n2_tau1 ;

  panelby n1/columns=5 spacing=15;

  vline n2/response=fe_power_l1_tau10 stat=mean lineattrs=(color=black pattern=solid) legendlabel="Level-1/tau1=0.0"; /*i've removed some vline references for simplicity*/

  rowaxis values=(0 to 1 by 0.1);

  refline 0.8/axis=y lineattrs=(color=black pattern=dash);

  label fe_power_l1_tau10="Statistical Power of Fixed Effect ^n Parameter Estimates" n2='Level-2 Sample Size';

  keylegend / across=2 down=2;

  format n1 n1size.;

  title '  ';


ods _all_ close;

Any help or ideas is greatly appreciated.  Ideally, i'd like to be able to accomplish this using the code i have in place (without having to migrate to statgraph under proc template).

Cynthia already provided some guidance (i'll paste below), but she also suggested i post here.  I found Dan Heath's paper on annotating graphs, but i'm not running 9.3 yet Smiley Sad 

Here are Cynthia's suggestions:


  You might want to pose this question in the ODS GRAPHICS forum, to find out what future development plans are or whether there's a current workaround (depending on your version of SAS). However, in the documentation,

it says:

"Inline Formatting with ODS Statistical Graphics

ODS Statistical Graphics  include template-based procedures (SGPLOT, SGPANEL, and SGSCATTER) and some statements that support ODS ESCAPECHAR in conjunction with the UNICODE, SUB, and SUP inline formatting functions. Refer to SAS ODS Graphics: Procedures Guide and SAS Graph Template Language: User's Guidefor information about how to use these functions with ODS Statistical Graphics. "        

which implies to me that the only ESCAPECHAR functions that you can use are the ones that are mentioned in that paragraph. The "new" syntax for inserting a line feed into TABULAR output is ^{newline 1} -- instead of ^n, as you show. But I tried ^{newline 1} and it doesn't work in the Axis label either.

  If you search the "Graphically Speaking" blog by Sanjay@sas, you will find a post (on May 25, 2012) about splitting the X axis tick values. Not exactly what you were asking, but he does discuss an interesting feature that's coming for 9.4 to TickValueFitPolicy called "SplitAlways".  I don't know whether they have implemented anything similar for the axis labels or not.

  There may be a way to annotate more lines of text onto the image (in place of the AXIS label), since ESCAPECHAR methods don't seem to work. You'd have to work with Tech Support to find out for sure. ANNOTATE with ODS GRAPHICS works very similar to ANNOTATE with "classic" SAS/GRAPH. The advantage of an ANNOTATE approach, it that it would leave your present approach intact but might add the ability to annotate your label text as 2 lines instead of 1. Either reposting your question in the ODS GRAPHICS forum or working with Tech Support would be your best bet for help.


Meteorite | Level 14

No, you cannot get an axis label wrapped into multiple lines.  This has been requested, and you can add your voice to it by calling in to Tech Support.  You can use escaped unicode text in the label, but not the actions like Sup and Sub.

Possible workarounds:

  • At SAS 9.3, use annotate.
  • I have suggested to users that for splitting simple X axis, you could use the footnote to render the 2nd line of the label.  Just provide the first line to the axis label, and use a center aligned footnote(s) to render the remaining text.
  • I can't think of some way to do the same for Y  or Row axis labels.
  • I don't understand your code with label statement.

The splitting Cynthia alludes to at SAS 9.4 is for tick values, data labels and curve labels.  Not for axis labels.  The reason for this is that axis labels are handled by low level framework code and any change has to be done carefully to account for all possible side effects.  It is on our list of items for a future release.

Obsidian | Level 7


Sorry it took so long for me to reply...i had to wait for my university to distribute the 9.3 version.  Anyway, i just wanted to post my updated code to share with others so they can see how i handled it.  Thanks again for the annotate tip.

Here's the code:

**create annotate data set for wrapping y-axis label;

**note the two separate data lines in the annotate data set that split the label in two;

**the wrapping occurs by changing the x-coordinate for the first line (-1) and the second line (2);

data anno;

  retain function 'text' x1 y1 justify width textsize;

  input x1 y1 justify $11-16 width rotate textsize label $26-71 ;


  -1 60 Center 50 90 12 95% CI Coverage of Fixed Effect

  2 60 Center 50 90 12 Parameter Estimates ;


ods graphics/reset imagename="figure9" border=off height=5.5in width=9.0in scale=on;

proc sgpanel data=vccover pad=(left=3%) sganno=anno; /*the command to use the annotate dataset*/

  panelby vc n1 /columns=5 rows=2 spacing=15;

  vline n2/response=vci_cover_rsp_tau01 stat=mean lineattrs=(color=mediumblue pattern=solid) legendlabel="tau0=.1/RSPL";

  vline n2/response=vci_cover_rsp_tau05 stat=mean lineattrs=(color=mediumblue pattern=dash) legendlabel="tau0=.5/RSPL";

  vline n2/response=vci_cover_lap_tau01 stat=mean lineattrs=(color=maroon pattern=solid) legendlabel="tau0=.1/LAP";

  vline n2/response=vci_cover_lap_tau05 stat=mean lineattrs=(color=maroon pattern=dash) legendlabel="tau0=.5/LAP";

  vline n2/response=vcs_cover_rsp stat=mean lineattrs=(color=darkgreen pattern=solid) legendlabel="RSPL";

  vline n2/response=vcs_cover_lap stat=mean lineattrs=(color=purple pattern=solid) legendlabel="LAP";

  rowaxis values=(.85 to 1 by 0.05) label=" ";  /*this prevents the default y-axis label*/

  refline 0.95/axis=y lineattrs=(color=black pattern=dash);

  label n2="Level-2 Sample Size";

  keylegend / across=2 down=3;

  format n1 n1size. vc vcpanel.;

  title ' ';


Meteorite | Level 14

I'm not sure how intricate your arrangement of paneled graphs needs to be, but if it's something fairly simple then you might could use "ods htmlpanel" and gplot (or gchart) such as:

And then you could use an axis statement such as the following to split the axis label text into multiple lines:

axis1 label=(justify=center 'y line 1' justify=center 'y line 2');
axis2 label=(j=c 'x axis line 1' j=c 'x axis line 2');

proc gplot data=sashelp.class;
plot height*weight / vaxis=axis1 haxis=axis2;




The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.


Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 


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
  • 3 in conversation