0
votes

This can be achieved using ODS, but I have a constraint that I am not supposed to use ODS as I'm using Listing. I need to generate RTF reports which has super and subscript text in them. Below is the sample code which I was referring which uses ODS.

ods rtf file='temp.rtf';
ods escapechar='^';

proc print data=sashelp.class;
  title 'this value is superscripted ^{super 2} ';
  title2 'this value is subscripted ^{sub 2} ';
run;

ods rtf close;

I want to print superscript or subscript text in Proc report title or footnotes.

2
Wait, I really don't understand this now that I read it again. LISTING is different from RTF, they're unrelated to each other. Can you explain the constraint in more detail (verbatim, if possible, particularly if this is a homework question)?Joe

2 Answers

1
votes

Silly constraint calls for equally silly solution - who needs ODS escapechar when you can hard-code the rtf control sequences for subscripts and superscripts?

x 'cd c:\temp';
/*Produce initial rtf without superscripts / subscripts*/
ods rtf file='temp.rtf';

proc print data=sashelp.class;
  title 'this value is superscripted 2';
  title2 'this value is subscripted 2';
run;

ods rtf close;

/*Add them in manually as per .rtf file format specification*/
data _null_;
    infile "c:\temp\temp.rtf" lrecl = 32767;
    file "c:\temp\want.rtf";
    input;
    length rtf $32767;
    rtf = _infile_;
    rtf = tranwrd(rtf, 'this value is superscripted 2', 'this value is superscripted \super 2 \nosupersub');
    rtf = tranwrd(rtf, 'this value is subscripted 2', 'this value is subscripted \sub 2 \nosupersub');
    put rtf;
run;
0
votes

I don't believe this is possible in ODS LISTING. (Anyone who tells you you aren't using ODS is wrong, because listing is an ODS output destination just like all of the other destinations, but i'm assuming you mean you can't use anything other than ODS Listing, or use some of the common ODS tricks like ODS ESCAPECHAR).

However, ODS Listing doesn't have much available to it in terms of playing with fonts. You can put a super-2:

ods listing;
proc print data=sashelp.class;
title "Fun²";
run;
ods listing close;

by literally typing the character into your text, but that's not available for every possible superscript, and I don't think there are subscript equivalents in the listing font.

You can find a listing of characters online, for example in this paper. You can insert them with '##'x where ## is the 2 digit hex code for the character, or by typing them (alt+0178 for ² for example, or use character map to find them; make sure you use the right font.)