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

Hello, 

 

I am trying to produce some figures for a manuscript I am working on and am trying to figure out a better way to do superscripting with axis or even category labels. Right now I create labels and then am using an annotate dataset to position superscripts. Its cumbersome and I assume there is a more streamlined way. Would love some help!

 

Example from the code I'm working on: 


input y sys system$ SysOut AveOut;
length name $ 15;

Label SysOut = "Cropping System Output (Gcal ha )";
Label AveOut = "Mean Output (Gcal ha )";

if sys=1 then do; name='Maize'; end;
if sys=2 then do; name='M-S'; end;
if sys=3 then do; name='M-S-W (org)'; end;
if sys=4 then do; name='M-a-A-A'; end;
if sys=5 then do; name='M-o/A-A (org)'; end;

run;


data anno1;
length function $20. label $200.;

function="text"; label="(*ESC*){sup '-1'}";
rotate = 0;
X1 = 77; Y1 = 3; ANCHOR = "right";
width = 30; *TEXTSIZE = 11;
output;

function="text"; label="(*ESC*){sup '-1'}";
rotate = 90;
X1 = 2; Y1 = 87; ANCHOR = "right";
width = 30; *TEXTSIZE = 11;
output;

run;

 

ods graphics / width = 4in height=4in noborder;
ods html dpi=200;
ods graphics on / noborder width = 4in height=4in outputfmt=png;
ods html dpi=500;

proc sgplot
data=FW

description=" "
sganno=anno1;
title;

styleattrs
datasymbols=(circle diamond diamondfilled triangle trianglefilled)
datacontrastcolors=(red green orange blue gray);
xaxis labelattrs=(color=black size=11pt);
yaxis labelattrs=(color=black size=11pt);

reg x=AveOut y=SysOut / nomarkers group = sys;
scatter x=AveOut y=SysOut / group = name;
lineparm x=6 y=6 slope=1;
keylegend / position=top location=inside noborder EXCLUDE=("system" "1" "2" "3" "4" "5" "LineParm") ;

run;

 

and figure generated:

 

Fig1.png

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

Hi @grsanford ,

 

You don't need to use annotate to do superscript. You can do it within the XAXIS and YAXIS statement. 


Please see Dan Heath's blog on unicode:

https://blogs.sas.com/content/graphicallyspeaking/2011/11/14/the-power-of-unicode/

 

 

View solution in original post

5 REPLIES 5
djrisks
Barite | Level 11

Hi @grsanford ,

 

You don't need to use annotate to do superscript. You can do it within the XAXIS and YAXIS statement. 


Please see Dan Heath's blog on unicode:

https://blogs.sas.com/content/graphicallyspeaking/2011/11/14/the-power-of-unicode/

 

 

DanH_sas
SAS Super FREQ

I addition to what I described in the blog referred to by @djrisks , you can now embed special characters (including superscript/subscript characters) in a format and have them honored in the graph. Here is an example using the "less than or equal to" character:

proc format;
value agefmt 20-<30 = "20 (*ESC*){unicode '2264'x} 30"
             30-<40 = "30 (*ESC*){unicode '2264'x} 40"
             40-<50 = "40 (*ESC*){unicode '2264'x} 50"
             50-<60 = "50 (*ESC*){unicode '2264'x} 60"
             60-<70 = "60 (*ESC*){unicode '2264'x} 70"
;
run;

Title "Cholesterol Level by Age and Gender";
proc sgplot data=sashelp.heart;
format ageAtStart agefmt.;
vbox cholesterol / category=ageAtStart group=sex;
xaxistable cholesterol / stat=mean class=sex classdisplay=cluster location=inside
           label="Chol. (mean)";
keylegend / location=inside position=topright;
run;

In your case, you have a continuous axis, so this might not help you much; but you mentioned wanted to do this for categorical labels, so I wanted to mention this functionality for completeness.

 

Thanks!

Dan

grsanford
Fluorite | Level 6

Dan, 

 

Thank you very much. I am getting close but have run into an issue with superscript minus. You mention in your blog post the need to have a font style with a full suite of unicode characters. I assume that my currently problem is that I am not using an appropriate font. Can you help me understand how I can change that? Thank you again. 

 

proc sgplot
data=FW

description=" ";
title;

styleattrs
datasymbols=(circle diamond diamondfilled triangle trianglefilled)
datacontrastcolors=(red green orange blue gray);
xaxis labelattrs=(color=black size=11pt) label= "Mean Output (Gcal ha (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x})";
yaxis labelattrs=(color=black size=11pt) label= "System Output (Gcal ha (*ESC*){unicode '207B'x}(*ESC*){unicode '00B9'x})";

reg x=AveOut y=SysOut / nomarkers group = sys;
scatter x=AveOut y=SysOut / group = name;
lineparm x=6 y=6 slope=1;
keylegend / position=top location=inside noborder EXCLUDE=("system" "1" "2" "3" "4" "5" "LineParm") ; *valueattrs=(color=black size=11pt) ;

run;

 

Fig1.png

DanH_sas
SAS Super FREQ

In your LABELATTRS, set FAMILY="Arial Unicode MS" and see if that look okay to you.

grsanford
Fluorite | Level 6

That worked brilliantly. Thank you. 

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
  • 5 replies
  • 4236 views
  • 2 likes
  • 3 in conversation