BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RyanSimmons
Pyrite | Level 9

When using PROC SGPLOT, it is simple enough to get unicode (or other special characters) in the labels for the legends. This can be accomplished in at least two ways; one by defining a style in PROC TEMPLATE (e.g. this example), or by specifying the labelattrs=GraphUnicodeText option (e.g. this example).

 

However, so far as I can tell, there is no similar method for getting these special characters to appear in the legend for PROC SGPLOT. Specifying the GraphUnicodeText option for the valueattrs in the KEYLEGEND statement has no apparent effect. Similarly, using the same PROC TEMPLATE approach as in the link I provided does not seem to impact the legend. The text still prints out the full "{unicode '2081'x}", etc. (And, no, the problem isn't with a misspecifed unicode or the wrong ODS ESCAPECHAR, because I can use the same exact unicode on the axis labels and have it appear as desired).

 

Does anybody have any idea how to force PROC SGPLOT to recognize unicode characters in the legend? What is it about the way SAS is rendering the legend that makes it different from the axes labels, such that it ignores the unicode commands? The traditional approaches don't seem to work, and I can't find any description of how to do this by searching around.

 

Here is a quick arbitrary example to demonstrate the problem:

 

proc format;

value uni 1="log~{unicode '2081'x}~{unicode '2080'x}x"

2="log~{unicode '2081'x}~{unicode '2080'x}y";

run;

data _example;

do x=1 to 10;

y=int(ranuni(0)*100);

if y>50 then g=2; else g=1;

output;

end;

format g uni.;

run;

ods escapechar='~';

proc sgplot data=_example;

xaxis minor label="log~{unicode '2081'x}~{unicode '2080'x}x"

labelattrs=GraphUnicodeText;

yaxis minor label="log~{unicode '2081'x}~{unicode '2080'x}y"

labelattrs=GraphUnicodeText;

scatter x=x y=y / group=g;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

As with anything Graph related, Sanjay and his blog have the answer:

http://blogs.sas.com/content/graphicallyspeaking/?s=unicode+legend

 

 

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

As with anything Graph related, Sanjay and his blog have the answer:

http://blogs.sas.com/content/graphicallyspeaking/?s=unicode+legend

 

 

RyanSimmons
Pyrite | Level 9

Well, first of all let me say I am suprirsed that this article didn't appear when I Googled "PROC SGPLOT UNICODE LEGEND". My Google-fu is weak.

 

Thanks!

RyanSimmons
Pyrite | Level 9

I guess I posted too soon. I can't replicate his examples. Apparently, this functionality only works with "SAS 9.4 Maintenance release 3". Otherwise, these options won't work at all. Any idea if there is a workaround?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, quite a bit of functionality came in for th 9.4 release with graphs.  Personally, I do not know of a way to do this.  You could post a comment on that post, but I think the best suggestion is to move to 9.4, it has plenty of new functionality.

RyanSimmons
Pyrite | Level 9

I actually DO have 9.4, the problem is I only have 9.4 maintenance release 2, whereas apparently for this very specific functionality I need release 3. So close, yet so far! I'll have to talk to my department about getting upgraded. Thanks!

djrisks
Barite | Level 11

Hi Ryan,

One way that Unicode can be adding in to the legend with the current version of SAS you have is to use GTL and to use the legendlabel in Scatterplot, and also to use the option valueattrs = GraphUnicodeText in the discretelegend statement. With legendlabel you can include the unicode similarly to how you would do in in a label within the titles. The only thing is that if you have grouped data you need to unstack it first to add the separate unicode value in the legend, which has effectively been done with the expressions below.

 

 

proc template;
  define statgraph unicodelegend;
    begingraph;
   layout overlay / yaxisopts = (label = "log~{unicode '2081'x}~{unicode '2080'x}y" labelattrs=GraphUnicodeText) xaxisopts = (label="log~{unicode '2081'x}~{unicode '2080'x}x"  labelattrs=GraphUnicodeText);


     scatterplot y = eval(ifn(g = 1, y, .)) x = eval(ifn(g = 1, x, .)) / name = "leg" legendlabel = "log~{unicode '2081'x}~{unicode '2080'x}x"  markerattrs = (color = GRAPHDATA1:contrastcolor symbol = GRAPHDATA1:markersymbol);
	 scatterplot y = eval(ifn(g = 2, y, .)) x = eval(ifn(g = 2, x, .)) / name = "leg2" legendlabel = "log~{unicode '2081'x}~{unicode '2080'x}y"  markerattrs = (color = GRAPHDATA2:contrastcolor symbol = GRAPHDATA2:markersymbol);

  discretelegend "leg" "leg2" / valueattrs = GraphUnicodeText;
   endlayout;
endgraph;
  end;
run;

proc sgrender data = _example template = unicodelegend;
run;

 


unicodeexample.png

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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