Hi,
I have defined a FORMAT that uses unicode superscripts:
proc format;
value agegroupfr 1="1(*ESC*){super re} fois"
2="2(*ESC*){super e} fois ou plus"
3="18–24"
4="25–34"
5="35–44"
6="45–54"
7="55–64"
8="65–74"
9="75+"
10="Toutes";
run;
I want to use this format to be used to label values on the y-axes of a butterfly plot. Here is the portion of the code where I define the y-axes:
yaxis reverse
display=(noticks)
valueattrs=(color=gray33 size=10pt family="Arial Unicode MS")
labelposition=top
colorbands=odd colorbandsattrs=(color=grayf3)
label="&aglab."
valuesformat=&agfmt.;
y2axis reverse
type=discrete
display=(noticks)
valueattrs=(color=gray33 size=10pt family="Arial Unicode MS")
labelposition=top
label="&aglab."
valuesformat=&agfmt.;
The result is not what I expected:
I have tried several solutions proposed in this forum, but with no effect. What am I doing wrong?
Thanks.
I don't think it can be done normally, so I would suggest looking into annotation which allows all superscripts and Unicode. Here is a link to SG annotation dataset information: link
The following example I make an annotation dataset and make the normal tick values white so they can't be seen (but still create the graph space for them). I then use annotation to draw new y-axis tick values with the wanted superscripts.
proc format;
value xx
80='80(*ESC*){Sup "e"}'
60='60(*ESC*){Sup "er"}';
run;
data yaxis;
length function $ 8 label $ 25;
do i = 60 to 140 by 20;
function="text"; x1=-5; y1=i; x1space="datapercent";y1space="Datavalue";
label=strip(put(i,xx.));size=10;textcolor='black';
output;
end;
/* create observation to draw the title */
do i = 60 to 140 by 20;
function="text"; x1=105; y1=i; x1space="datapercent";y1space="Datavalue";
label=strip(put(i,xx.));size=10;textcolor='black';
output;
end;
drop i;
run;
ods graphics / reset;
proc sgplot data=sashelp.class sganno=yaxis;
scatter x=height y=weight;
scatter x=height y=weight / y2axis markerattrs=(size=0pt);
yaxis valueattrs=(color=white) labelposition=top ;
y2axis valueattrs=(color=white) display=(nolabel) ;
run;
Have you tried this suggestion: https://communities.sas.com/t5/Graphics-Programming/Superscript-in-axis-label-SGPLOT/td-p/529656
I'm also assuming you have the ODS ESCAPECHAR set somewhere else since you haven't shown your full code.
I'll move your post to the graphics forum, but it would probably help if you could include some data and the full code so someone can replicate your issue. Or make a simpler example using sashelp.class if necessary.
FYI - it seems SUPER/SUB are not supported in AXIS statements but you can use the Unicode characters instead if it's available.
I have tried setting
ods escapechar="^";
And redefining the format as
proc format;
value agegroupfr 1="1^{super re} fois"
2="2^{super e} fois ou plus"
3="18–24"
4="25–34"
5="35–44"
6="45–54"
7="55–64"
8="65–74"
9="75+"
10="Toutes";
run;
No superscripts there either.
Thank you for your help, but nope:
proc format;
value agegroupfr 1="1^{unicode '1d49'x} fois"
2="2(*ESC*){unicode '1d49'x} fois ou plus"
3="18–24"
4="25–34"
5="35–44"
6="45–54"
7="55–64"
8="65–74"
9="75+"
10="Toutes";
run;
Result:
Simplified example so anybody can try:
Creating the unicode format:
proc format;
value unitest 0="^{unicode '0024'x}"
1="^{unicode '0040'x}";
run;
Creating the dataset:
data have;
x=0;
y=0;
output;
x=1;
y=1;
output;
format y unitest.;
run;
proc print data=have;
run;
Looks good so far:
Obs | x | y |
---|---|---|
1 | 0 | $ |
2 | 1 | @ |
Now, let's try to plot it:
ods escapechar="^";
proc sgplot data=have;
scatter x=x y=y;
yaxis display=(noticks) valueattrs=GraphTextUnicode;
run;
aaand....
*sad_trombone.mp3*
I don't think it can be done normally, so I would suggest looking into annotation which allows all superscripts and Unicode. Here is a link to SG annotation dataset information: link
The following example I make an annotation dataset and make the normal tick values white so they can't be seen (but still create the graph space for them). I then use annotation to draw new y-axis tick values with the wanted superscripts.
proc format;
value xx
80='80(*ESC*){Sup "e"}'
60='60(*ESC*){Sup "er"}';
run;
data yaxis;
length function $ 8 label $ 25;
do i = 60 to 140 by 20;
function="text"; x1=-5; y1=i; x1space="datapercent";y1space="Datavalue";
label=strip(put(i,xx.));size=10;textcolor='black';
output;
end;
/* create observation to draw the title */
do i = 60 to 140 by 20;
function="text"; x1=105; y1=i; x1space="datapercent";y1space="Datavalue";
label=strip(put(i,xx.));size=10;textcolor='black';
output;
end;
drop i;
run;
ods graphics / reset;
proc sgplot data=sashelp.class sganno=yaxis;
scatter x=height y=weight;
scatter x=height y=weight / y2axis markerattrs=(size=0pt);
yaxis valueattrs=(color=white) labelposition=top ;
y2axis valueattrs=(color=white) display=(nolabel) ;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.