BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi, Me again!

Correct me if I missed an option.

Create a line break in legend items is not possible.

The solution with escape character working in an axis label won't work in legend items.

There is no fitpolicy option when it comes to the keylegend statement or legenditem statement.

 

ods escapechar='^' ;
proc format;
    value age 11-13='Group^Young'
              14-16='Group^Old';
run;

proc sort data=sashelp.class out=class;
    by sex age;
run;    

proc sgplot data=class;
    vbarbasic sex / response=height stat=mean group=age;
    format age age.;
    keylegend / position=right;
run;    

proc sgplot data=class;
    vbarbasic sex / response=height stat=mean group=age;
    format age age.;

    legenditem type=fill name='1'
              / label='Group^Young';
    legenditem type=fill name='2'
              / label='Group^Old';
    keylegend '1' '2'/ position=right;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Maybe a bit of a kludge

 

proc sgplot data=class ;
    vbarbasic sex / response=height stat=mean group=age;
    format age age.;

    legenditem type=fill name='1'
              / label='Group' fillattrs=graphdata1;
    legenditem type=text name='a'
              / label='Young';
    legenditem type=Fill name='2'
              / label='Group' fillattrs=graphdata2;
    legenditem type=text name='b'
              / label='Old';
    keylegend  '1' 'a' '2' 'b'/ position=right;
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You don't have the split in PROC FORMAT correct.

 

You want

 

ods escapechar='^' ;
proc format;
    value age 11-13="Group^{newline}Young"
              14-16="Group^{newline}Old";
run;

 

so this works in PROC PRINT and PROC REPORT and similar types of output.  Stealing from @Ksharp here, I can even get escape characters to work in SGPLOT in axis labels and titles and footnotes using the (*ESC*) delimiter, but I can't get it to work in SGPLOT legends.

 

proc sgplot data=class;
    vbarbasic sex / response=height stat=mean group=age;
    format age age.;
    keylegend / position=right;
    yaxis label="Height(*ESC*){unicode '000A'x}Inches";
run;    

 

Note: I can get other unicode characters to work where the line break is supposed to be. For example, if instead of the line break, I want a "greater than or equal to sign" (Unicode 2265) even though it makes no sense in this context, this code works inside of legends. It just doesn't seem to work for line breaks.

 

proc format;
    value age 11-13="Group(*ESC*){unicode '2265'x}Young"
              14-16="Group(*ESC*){unicode '2265'x}Old";
run;

 

 

 

--
Paige Miller
ballardw
Super User

Maybe a bit of a kludge

 

proc sgplot data=class ;
    vbarbasic sex / response=height stat=mean group=age;
    format age age.;

    legenditem type=fill name='1'
              / label='Group' fillattrs=graphdata1;
    legenditem type=text name='a'
              / label='Young';
    legenditem type=Fill name='2'
              / label='Group' fillattrs=graphdata2;
    legenditem type=text name='b'
              / label='Old';
    keylegend  '1' 'a' '2' 'b'/ position=right;
run;
DanH_sas
SAS Super FREQ

Correct -- there is not currently not an option to split legend labels. That being said, there are a couple of things to clear up for you regarding ODS ESCAPECHAR usage in ODS GRAPHICS.

  1. Specifying the ODS escapement in the string by itself has no effect -- you also have to specify a function. For ODS GRAPHICS, we support only the unicode function in text strings. For example, "alpha=^{unicode '03b1'x}". In the INSET statement and in annotation, we also support the sup and sub functions( "R^{sup '2'}"). For sup/sub support in the regular text strings, you need to use the sup/sub Unicode values.
  2. When using ods escapement in PROC FORMAT, you must use the default ODS ESCAPE sequence, which is (*ESC*). This sequence will work anywhere -- ODS ESCAPECHAR is just a way to define one character to do the same thing.
xxformat_com
Barite | Level 11
Thank you Dan

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 344 views
  • 5 likes
  • 4 in conversation