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

I am trying to get some special character in the graph but failed. Both superscript and supscript are not working.

 

My code is:

 

ods rtf file="C:\work\test.rtf";
goptions reset=all;
ods escapechar="^";
ods graphics on / attrpriority=none noborder;
PROC SGPLOT DATA = Srp2;
format tp tpa.;
styleattrs datacontrastcolors=(grey) datasymbols=(circlefilled trianglefilled circle) datalinepatterns=(solid longdash dot);

SERIES X = tp Y = mean/ group=surg_grp name="Surgical Method" lineattrs=(thickness=2) MARKERS markerattrs=(size=8 color=black);
XAXIS label="Time" TYPE = DISCRETE ;
YAXIS LABEL = "SR^{sub P} (2 Chamber) (s^{super -1})" VALUES = (0 TO 10 BY 1);
TITLE "SR^{sub P} (2 Chamber) Trend by Surgical Method";
keylegend "Surgical Method";
RUN; 
ods graphics off;
ods rtf close;

The graph is:

 

SGPlot.png

 

I did find some discussion about this but looks like it did not really solved!

https://communities.sas.com/t5/ODS-and-Base-Reporting/How-to-add-both-a-subscript-and-a-superscript-...

 

Anyone have any suggestion?

 

Thanks!

Andrea

1 ACCEPTED SOLUTION

Accepted Solutions
SuzanneDorinski
Lapis Lazuli | Level 10

Using an annotation data set might work.  In the program below, I used the SASHELP.CLASS data set.  

 

ods rtf 
    file='/folders/myfolders/ODS Graphics/subscripts_and_superscripts_via_annotations_PROC_SGPLOT.rtf'
    style=HTMLBlue; 
ods pdf file='/folders/myfolders/ODS Graphics/subscripts_and_superscripts_via_annotations_PROC_SGPLOT.pdf'; 


ods escapechar="^";
ods graphics on / attrpriority=none noborder;

* you can use data step coding to set up the annotations, but it can get complicated
* quickly. ;

data anno;
 infile datalines dlm='#';
 length function $ 8 label $ 50 drawspace $ 12 textweight $ 4 justify $ 6;
 input function $ drawspace $ rotate width textweight $ justify $ x1 y1 discreteoffset label $;
 datalines;         
 text # graphpercent # 90 # 50 # bold # center # 2 # 50 # -0.5 # SR^{sub 'P'} (2 Chamber) (s^{sup '-1'})
 text # graphpercent # 0 # 50 # bold # center # 50 # 98 # -0.5 # SR^{sub 'P'} (2 Chamber) Trend by Surgical Method
    ; 
run;

* used the pad option on PROC SGPLOT to create room for the annotations.  
* otherwise, they may end up jammed too close to the plot. ;

proc sgplot data=sashelp.class pad=(left=20 top=20) sganno=anno;
	scatter x=weight y=height;
	yaxis display=(nolabel);
run;

* SAS provides a bunch of macros to do annotation, which is the easier way! ;

%sganno;

%let yaxislabel=SR(*ESC*){sub 'P'} (2 Chamber) (s(*ESC*){sup '-1'});

%let titlelabel=SR^{sub 'P'} (2 Chamber) Trend by Surgical Method;

data anno_via_macros;
  %sgtext(drawspace="wallpercent", x1=-20, y1=40, width=70, rotate=0, 
          textweight="bold", justify="center",
          label="&yaxislabel");
  %sgtext(drawspace="wallpercent", x1=50, y1=105, width=70, rotate=0,
          textweight="bold", justify="center",
          label="&titlelabel");
run;

proc sgplot data=sashelp.class pad=(left=30pct top=10pct) sganno=anno_via_macros;
	scatter x=weight y=height;
	yaxis display=(nolabel);
run;

ods rtf close;
ods pdf close;

The y axis label text looks fine in the Results Viewer, but when I opened the RTF, the term involving the negative exponent was jumbled.  When I opened the PDF, there was a gap between the s and the negative exponent.

 

I tried adding some extra space to the left side of the graphic, so that the annotation for the y axis would fit if I didn't rotate it.  The term involving the negative exponent looks as expected in the RTF output.  

 

I found Dan Heath's paper Annotating the ODS Graphics Way! helpful in figuring this out. 

View solution in original post

2 REPLIES 2
SuzanneDorinski
Lapis Lazuli | Level 10

Using an annotation data set might work.  In the program below, I used the SASHELP.CLASS data set.  

 

ods rtf 
    file='/folders/myfolders/ODS Graphics/subscripts_and_superscripts_via_annotations_PROC_SGPLOT.rtf'
    style=HTMLBlue; 
ods pdf file='/folders/myfolders/ODS Graphics/subscripts_and_superscripts_via_annotations_PROC_SGPLOT.pdf'; 


ods escapechar="^";
ods graphics on / attrpriority=none noborder;

* you can use data step coding to set up the annotations, but it can get complicated
* quickly. ;

data anno;
 infile datalines dlm='#';
 length function $ 8 label $ 50 drawspace $ 12 textweight $ 4 justify $ 6;
 input function $ drawspace $ rotate width textweight $ justify $ x1 y1 discreteoffset label $;
 datalines;         
 text # graphpercent # 90 # 50 # bold # center # 2 # 50 # -0.5 # SR^{sub 'P'} (2 Chamber) (s^{sup '-1'})
 text # graphpercent # 0 # 50 # bold # center # 50 # 98 # -0.5 # SR^{sub 'P'} (2 Chamber) Trend by Surgical Method
    ; 
run;

* used the pad option on PROC SGPLOT to create room for the annotations.  
* otherwise, they may end up jammed too close to the plot. ;

proc sgplot data=sashelp.class pad=(left=20 top=20) sganno=anno;
	scatter x=weight y=height;
	yaxis display=(nolabel);
run;

* SAS provides a bunch of macros to do annotation, which is the easier way! ;

%sganno;

%let yaxislabel=SR(*ESC*){sub 'P'} (2 Chamber) (s(*ESC*){sup '-1'});

%let titlelabel=SR^{sub 'P'} (2 Chamber) Trend by Surgical Method;

data anno_via_macros;
  %sgtext(drawspace="wallpercent", x1=-20, y1=40, width=70, rotate=0, 
          textweight="bold", justify="center",
          label="&yaxislabel");
  %sgtext(drawspace="wallpercent", x1=50, y1=105, width=70, rotate=0,
          textweight="bold", justify="center",
          label="&titlelabel");
run;

proc sgplot data=sashelp.class pad=(left=30pct top=10pct) sganno=anno_via_macros;
	scatter x=weight y=height;
	yaxis display=(nolabel);
run;

ods rtf close;
ods pdf close;

The y axis label text looks fine in the Results Viewer, but when I opened the RTF, the term involving the negative exponent was jumbled.  When I opened the PDF, there was a gap between the s and the negative exponent.

 

I tried adding some extra space to the left side of the graphic, so that the annotation for the y axis would fit if I didn't rotate it.  The term involving the negative exponent looks as expected in the RTF output.  

 

I found Dan Heath's paper Annotating the ODS Graphics Way! helpful in figuring this out. 

Andrea_Peng
Obsidian | Level 7

Thanks, Suzanne! Create the data annon is working! I will have a look at Dan Heath's paper!

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
  • 2 replies
  • 3971 views
  • 1 like
  • 2 in conversation