You want to display this in the axis label or in a data label? ODS allows for Unicode characters, including super/subscripts.
/* Define sample data for the plot */
data sample;
do x=1 to 10;
y=int(ranuni(0)*100);
output;
end;
run;
/* Define the ODS escape character */
ods escapechar='^';
/* Define the attributes of the image file */
ods graphics / reset width=600px height=400px ;
title 'Using Subscripts and Superscripts';
proc sgplot data=sample;
scatter x=x y=y / markerattrs=(symbol=circlefilled color=blue);
/* Specify the 4-digit hex value for the subscript 2 and superscript 2 */
xaxis label="H^{unicode '2082'x}O^{unicode '00b2'x}";
/* Specify the 4-digit hex value for the superscript 2 and subscript 2 */
yaxis label="N^{unicode '00b2'x}H^{unicode '2082'x}";
run;
A footnote in the graph, like an inset?
inset "Inset footnote for AB^{sub '2'} "
/ textattrs=(size=12pt) position=bottomleft;
Can you post your actual SGPLOT code? No need for data but just want to see how many places you're talking about needing a subscript (different places need different methods).
If you want to show super or subscripts in SGPLOT graph statements (TEXT, VBAR, etc.) then you need to find them in Unicode form (I think DAN found one for subscript x). They still don't support direct super or subscripts in SGPLOT unfortunately. If you can find the character you want though in Unicode form then you can use the following method to get the values into a graph statement:
Basically instead of having character values that include the escape character and Unicode value you need to make a formatted variable where the format contains the escape character and Unicode value. It's an extra step I feel should be removed at some point by SAS but for now that is how it works.
We do currently support sup/sub in INSET statements in SGPLOT (as @ChrisHemedinger demonstrated); but, in other string situations (title, footnote, axis labels, legend labels, etc.), you must use a Unicode character to get sup/sub.
Here you go:
ods escapechar="~";
footnote f="Monotype Sans WT J" "This is an AB~{unicode '2093'x}";
proc sgplot data=sashelp.class;
scatter x=weight y=height;
run;
This key is choosing the correct font. The "2093' glyph is not available in every font -- only in the more "full-featured" fonts. If you are using san-serif fonts in your output, the font in the programs should work well for you.
Hope this helps!
Dan
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.