BookmarkSubscribeRSS Feed
Luna0571
Calcite | Level 5
I have tried every solution from the community. I am using SAS EG.
Ex: text to be displayed in graph is ABx . I want to display x as subscript in proc sg plot waterfall model.
8 REPLIES 8
ChrisHemedinger
Community Manager

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;

ChrisHemedinger_0-1594133889891.png

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Luna0571
Calcite | Level 5
Thanks Chris. But I want to display in footnote. In my example ABx is a text in one column. Wherever ABx comes into picture x should be subscript of AB.
ChrisHemedinger
Community Manager

A footnote in the graph, like an inset?

 

   inset "Inset footnote for AB^{sub '2'} " 
         / textattrs=(size=12pt) position=bottomleft;

ChrisHemedinger_0-1594138367354.png

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
JeffMeyers
Barite | Level 11

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).

Luna0571
Calcite | Level 5
Hi Jeff.
Let me keep it simple.I have a text variable the values are A,B,C,D for A,B I wanna display superscript & subscript for C,D respectively.
JeffMeyers
Barite | Level 11

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:

https://blogs.sas.com/content/sgf/2015/09/18/specifying-unicode-values-and-colors-is-easier-with-the...

 

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.

DanH_sas
SAS Super FREQ

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.

DanH_sas
SAS Super FREQ

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 7962 views
  • 6 likes
  • 4 in conversation