• Print  |
  • Feedback  |

FOCUS AREAS

Return to SAS Notes and Concepts for ODS

Base SAS

SAS Notes and Concepts for ODS

The RTF Destination


Overview

The RTF destination became production in Release 8.1 of the SAS System. This ODS destination creates output that can be read by various word processing packages including Microsoft Word and WordPerfect. As in the HTML destination, in RTF you can use PROC TEMPLATE to modify the colors, fonts, margins, and so forth. The PROC TEMPLATE documentation lists the available style elements and attributes. Some of the style elements and attributes are HTML-specific, but most can be used with the RTF destination as well. Unlike the HTML destination, the RTF destination creates only a body file.

The RTF specification is a method of encoding formatted text and graphics for transfer between applications and operating environments. The RTF file uses ANSI, PC-8, MAC, and IBM PC character sets. An RTF file consists of two main sections, <Header> and <Document>. The text is formatted by control words, control symbols, and groups.

A control word is a specially formatted command that RTF uses to mark printer control codes and document management information. Examples of control words are \b, which turns on bold, and \b0, which turns off bold.

Examples of control symbols are the nonbreaking space character \~ and the nonbreaking hyphen \_. Limited ability to add control words and symbols is supported in 8.2 by using the ODS ESCAPECHAR statement; see Enhancing Titles, Footnotes, and More with ESCAPECHAR= in this document.

A group consists of text and control words or control symbols contained within a set of braces { }. A group can specify how to format a portion of text or, more generally, how to format items such as fonts, styles, headers and footers, and even the document, section, paragraph, and character properties.

For more details, see the specifications of an RTF file.  

RTF Titles and Footnotes

Because, in ODS, titles and footnotes are written to the header and footer sections of an RTF file, the text might appear onscreen to have a faded gray color. This behavior exists even if you apply a style that modifies the color. However, the color is correct when viewed in the Print Preview window or when printed. In Release 8.1 and later, you can modify the style of each title or footnote individually by applying one of the following six options on the TITLE or FOOTNOTE statement. These options can be specified separately or together. Styles can also be applied globally to the titles and footnotes by creating a style template with PROC TEMPLATE.

BOLD
bolds the title or footnote
COLOR=
supplies the color of the title or footnote
BCOLOR=
supplies the background color of the title or footnote
FONT=
supplies the font for the title or footnote
HEIGHT=
supplies the point size for the title or footnote
JUSTIFY=
left-justifies, right-justifies, or centers the title or footnote
LINK=
specifies the hyperlink to use for the title or footnote
UNDERLIN=
specifies an underline

Here are some examples:

   title bold "this is a bold title";
   title2 justify=l "this title is left justified";
   title3 link="www.sas.com" "this is my hyperlink";
 

Enhancing Titles, Footnotes, and More with ESCAPECHAR=

Beginning with Release 8.2, The ODS ESCAPECHAR= statement greatly enhances the ability to add formatting and text in the RTF destination. For example, you can insert subscripts and superscripts or specify a style for each title or footnote.

Also, destination-specific information can be added to the title and footnotes by inserting raw text directly. For example, if you are generating both HTML and RTF from a procedure, the RTF-specific information is ignored by the HTML destination. Some escape character functions, such as {^SUB} and {^SUPER} are global within all destinations. See the ODS ESCAPECHAR statement in the SAS Output Delivery System: User's Guide, which is available in the Base SAS documentation.

Though the following examples use the TITLE statement, the same techniques can be used for footnotes and cell values. View an RTF file that contains output for the following examples.

Note: Because the path location might contain a backslash (\), you are advised to not use the backslash as an escape character.

Adding Superscripts and Subscripts

Here is an example that adds a superscript and a subscript.

   ods escapechar='^';
   ods listing close;

   options nodate number;
   footnote;

   ods rtf file="inline.rtf";
   proc print data=sashelp.class;
      title 'This value is superscripted^{super 2} ';
      title2 'This value is subscripted^{sub 2} ';
   run;

Adding Images

Beginning with Release 8.2, you can use the PREIMAGE= and POSTIMAGE= attributes to add an image to your RTF output.

   ods escapechar='^';
   proc print data=sashelp.class;
      title '^S={preimage="saslogo.jpg"} Logo';
   run;

Inserting Destination-Specific Raw Text

The following examples use the ODS ESCAPECHAR= statement together with the raw-text function R. The specification /RTF means that the raw text is passed only to RTF. Destinations other than RTF ignore the raw text. The first example passes tab characters.

   ods escapechar='^';
   proc print data=sashelp.class;
      title '^R/RTF"\tab\tab\tab\tab" This is a test';
   run;

The below example adds highlighting to the title.

   ods escapechar='^';
   proc print data=sashelp.class;
     title '^R/RTF"\highlight5" this is a test ';
   run;

The below example left-justifies (with the QL function) and splits the title over two lines.

   ods escapechar='^';
   proc print data=sashelp.class;
      title 'More text ^R/RTF"\line\ql" and more';
   run;
   ods rtf close;

ods listing;

Adding RTF Control Words

Beginning with Release 8.1, you can use RTF control words within the TITLE and FOOTNOTE statements. You must set the attribute PROTECTSPECIALCHARS=OFF so that ODS does not try to protect these characters. Set the attribute within the style element SystemTitle for the titles and Systemfooter for the footnotes. Below is a list of some commonly used control words. See the RTF specification for a complete list.

StyleRTF Control WordExample Code
Italicize \i title '\i italicized title';
Underline\ul title '\ul underline title';
Double underline \dul title '\dul title';
New line \line title 'this is the first \line this is the second ';
Bullet \bullet title '\bullet bullet preceding title';
Emboss \embo title '\embo embossed title';
Engrave \impr title '\impr engraved title';
Subscript \sub title 'This is a subscript T\sub 1';
Superscript \super title 'This is a subscript T\super 2';
Outline \outl title '\outl This is outlined';
Shadow \shad title '\shad This is shadowed';
Strike \strike title '\strike This is striked';
double strike \strikedl  
dotted underline \uld title '\uld dotted underline';
Wave underline \ulw title '\ulw wave underline';
Thick underline \ulth title '\ulth thick underline';
foreground color \cfn title '\cf2 foreground color';
Font size in half points\fs24 title '\fs40 fonts increased';
Highlight \highlightN title '\highlight2';
Bold \b title '\b bold title';
Left aligned \ql title '\ql left aligned.
Right aligned\qr title '\qr right aligned.
centered \qc title '\qc left aligned.

The control words can be combined within the TITLE and FOOTNOTE statements as in the example below, which left-justifies, underlines, and splits the title over two lines. View output.

   proc template;
      define style styles.test;
         parent=styles.rtf;
         style systemtitle from systemtitle /
               protectspecialchars=off;
      end;
   run;

   ods rtf body='temp.rtf' style=styles.test;

   proc print data=sashelp.class;
      title '\ul\ql this is the first \line this is the second';
   run;

   ods rtf close;

   

Using PROC TEMPLATE to Create Global Styles

You can use PROC TEMPLATE to create styles globally. However, if you apply options on a TITLE, FOOTNOTE, or GOPTION statement, they override the PROC TEMPLATE styles. If multiple styles are defined, here is the order of precedence, the higher items overriding the lower ones:

  1. locally, an option on the TITLE or FOOTNOTE statement
  2. an option on the GOPTIONS statement (such as FTEXT)
  3. a definition in PROC TEMPLATE.

Below is a style template created with PROC TEMPLATE that changes the foreground color to red and left-justifies the titles.

   proc template;
     define style styles.test;
       parent=styles.rtf;
       style systemtitle from systemtitle /
             just=left
             foreground=red;
     end;
   run;

   ods rtf body='temp.rtf' style=styles.test;

   proc print data=sashelp.class;
   run;

   ods rtf close;
   
 

RTF Colors

The RTF destination uses the style template STYLES.RTF by default. STYLES.RTF inherits its fonts and four basic colors from the style template STYLES.PRINTER. The style element Color_list supplies all of the colors for the RTF destination. See the Colors Concepts for an explanation of the shorthand way that colors are assigned, as well as instructions for modifying colors.

 

RTF Fonts

The fonts for the style template STYLES.RTF are inherited from the style template STYLES.PRINTER, within the style element Fonts. In a shorthand method like that for colors, the string 'TitleFont' defines the fonts associated with the titles and footnotes. By default the titles and footnotes have a font_face=Times, a font_size=12pt, a font_weight=bold, and a font_style=italic. The string "docFont" associates fonts responsible for the cell values. The string "headingFont" associates the fonts responsible for the column headings.

When specifying a font size for the RTF destination, be sure to include the unit of measure PT, for points. This allows the size that you specify to carry over in Word. Most word processors use PT as the default unit of measure. Here is the Fonts style element from the style template STYLES.RTF:

   replace fonts /
           'TitleFont2' = ("Times",12pt,Bold Italic)
           'TitleFont' = ("Times",13pt,Bold Italic)
           'StrongFont' = ("Times",10pt,Bold)
           'EmphasisFont' = ("Times",10pt,Italic)
           'FixedEmphasisFont' = ("Courier New, Courier",9pt,Italic)
           'FixedStrongFont' = ("Courier New, Courier",9pt,Bold)
           'FixedHeadingFont' = ("Courier New, Courier",9pt,Bold)
           'BatchFixedFont' = ("SAS Monospace, Courier New, Courier",6.7pt)
           'FixedFont' = ("Courier New, Courier",9pt)
           'headingEmphasisFont' = ("Times",11pt,Bold Italic)
           'headingFont' = ("Times",11pt,Bold)
           'docFont' = ("Times",10pt);
  


RTF FAQ

Modifying the style template is done in the same way as in the HTML destination. As mentioned earlier, you can take advantage of inheritance from the style template STYLES.RTF and build on it. The examples in this document are specific to the RTF destination.

The concepts remain above, but the FAQs have been moved.
All PROC TEMPLATE FAQ have been added to the support.sas.com SAS Notes application for greater usability.
Check it out!

See the ODS RTF section.