support.sas.com > Communities > Base
 
SAS - The power to know(tm)
 
Base SAS Community Home  
PROC TEMPLATE FAQ and Concepts  



 

PROC TEMPLATE FAQ and Concepts

The RTF Destination

Updated 25 November 2002


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

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 Simple In-Line Formatting for details.

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.

Adding Superscripts and Subscripts

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

   ods escapechar='\';
   proc print data=sashelp.class;
      title 'this value is superscripted \{super 2} ';
      title '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. In the TITLE statement below, J=L specifies a style (left justification), and the PREIMAGE= attribute specifies an image. Because the path location contains a backslash (\), a different escape character is needed.

   ods escapechar='^';
   proc print data=sashelp.class;
      title j=l '^S={preimage="C:\WINDOWS\Desktop\V7image.jpg"} a test';
   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 \QL) and splits the title over two lines.

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

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.

Style RTF Control Word Example 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 Overview and FAQ 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);
  
BACK

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.

RC1-How can I modify the colors of my cell values from white to gray?

Modifying the colors of the cell values can be accomplished by replacing the value associated with the string 'bg' in the Color_list style element. This can also be done by modifying the style element Data, which is shown below. View output.

   proc template;
     define style styles.newrtf;
       parent=styles.RTF;
       style Data from Data /
             background=graybb;
     end;
   run;

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

   proc print data=sashelp.class;
     title 'Modifying the cell colors';
   run;

   ods rtf close;
BACK

RC2-How can I change the background color of the column headers from gray to white?

The background colors of the headers can be changed to white by modifying the argument associated with the string 'bgH', as shown below. The default value for this string is 'graybb'. This could also be done by modifying the style element Header, which is responsible for rendering the header. View output.

   proc template;
     define style styles.newrtf;
       parent=styles.RTF;
       replace color_list
              "Colors used in the default style" /
              'link'= blue
           /* 'bgH'= graybb */
              'bgH'= white
              'fg' = black
              'bg' = white;
     end;
   run;

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

   proc freq data=sashelp.class;
   title 'changing the header background to white';
   run;

   ods rtf close;
BACK

RC3-How can I modify the foreground colors of the RTF document?

The foreground colors can be modified by replacing the argument associated with the string 'fg'. View output.

   proc template;
     define style styles.newrtf;
       parent=styles.RTF;
       replace color_list
               "Colors used in the default style" /
               'link'= blue
               'bgH'= white
             /*'fg' = black */
               'fg' = blue
               'bg' = white;
     end;
   run;

   ods rtf body='rc3.rtf' style=styles.newrtf;

   proc freq data=sashelp.class;
     title 'modifying the foreground color';
   run;

   ods rtf close;
BACK

RF1-How can I modify the font style of the titles from italic bold to regular bold?

The font style for the titles and footnotes can be changed by modifying the argument associated with the string 'TitleFont'. The font style "italic" can be removed from the argument; see example 1. This can also be done by directly modifying the style element SystemTitle; see example 2.

   /* Example 1 */

   proc template;
     define style styles.newrtf;
       parent=styles.rtf;
       replace fonts /
               'TitleFont2' = ("Times",12pt,Bold Italic)
               'TitleFont' = ("Times",13pt,Bold )
             /*'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);
     end;
   run;

   ods rtf body='rf1.rtf' style=styles.newrtf;

   proc freq data=sashelp.class;
     title 'modifying the foreground color';
   run;

   ods rtf close;


   /* Example 2 */

   proc template;
     define style styles.newrtf;
       parent=styles.rtf;
       style SystemTitle from Titlesandfooters /
             font = ("Times",13pt,Bold );
     end;
   run;

   ods rtf body='rf1.rtf' style=styles.newrtf;

   proc freq data=sashelp.class;
     title 'modifying the title font';
   run;

   ods rtf close;
 
BACK

RF2-How can I change the fonts of the cell values?

The fonts of the cell values can be changed by modifying the value associated with the string 'docFont'; see example 1. This can also be done by modifying the style element Data; see example 2.

   /* Example 1 */

   proc template;
     define style styles.newrtf;
       parent=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);   */
              'docFont' = ("Times",8pt);
     end;
   run;

   ods rtf body='rf2.rtf' style=styles.newrtf;

   proc print data=sashelp.class;
     title 'Modifying fonts for cell values';
   run;

   ods rtf close;


   /* Example 2 */

   proc template;
     define style styles.newrtf;
       parent=styles.rtf;
       style data from data /
             font= ("arial",10pt);
     end;
   run;

   ods rtf body='rf2.rtf' style=styles.newrtf;

   proc print data=sashelp.class;
     title 'Modifying fonts for cell value';
   run;

   ods rtf close;
  
BACK

RF3-How can I change the fonts of the column headers?

The fonts for the column headers can be changed by modifying the fonts associated with the string 'headingFont'; see example 1. This can also be done by modifying the style element Header; see example 2. View output.

   /*  Example 1 */

   proc template;
     define style styles.newrtf;
       parent=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) */
               'headingFont' = ("Times",11pt,Bold italic)
               'docFont' = ("Times",10pt);

     end;
   run;

   ods rtf body='rf3.rtf' style=styles.newrtf;

   proc freq data=sashelp.class;
     title 'Modifying the fonts for the column headers';
   run;

   ods rtf close;


   /* Example  2 */

   proc template;
     define style styles.newrtf;
       parent=styles.rtf;
       style header from header /
             font=("Times",11pt,Bold italic);
     end;
   run;

   ods rtf body='rf3.rtf' style=styles.newrtf;

   proc freq data=sashelp.class;
     title 'Modifying the fonts for the column headers';
   run;

   ods rtf close;
  
BACK

RTF1-Where can I find documentation on the RTF destination?

For more information about the RTF destination, see the SAS online help.

BACK

RTF2-How can I remove the grid lines from within the table and the box from around the table?

The grid lines can be removed from within the table by specifying the attributes RULES=NONE and BACKGROUND=_UNDEF_. The rules showing between the cells are the background color of the table. By default in 8.1, the background color of the table is black. Specifying the attribute BACKGROUND=_UNDEF_ treats the attribute as if it were never set. The attribute FRAME=VOID removes the box from around the table. View output.

   proc template;
     define style styles.test;
       parent=styles.rtf;
       style Table from Output /
             Background=_Undef_
             Rules=NONE
             frame=void;
     end;
   run;

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

   proc freq data=sashelp.class;
     title 'Remove grids from the table and the box around the table';
   run;

   ods rtf close;
 
BACK

RTF2A-How can I remove all of the grid lines from within the table except from beneath the column headers?

To remove all of the grid lines except the ones beneath the column headers, use the RULES=GROUPS attribute within the style element Table. Issue the BACKGROUND=_UNDEF_ attribute to prevent the background color of the table from showing, and issue the FRAME=VOID attribute to remove the box from around the table. To remove the shading from both the column headers and the row headers, specify the attribute BACKGROUND=_UNDEF_ within the style elements Header and Rowheader, respectively. View output.

   proc template;
     define style styles.TEST;
       parent=styles.rtf;
       style Table from output /
             Background=_UNDEF_
             Rules=groups
             Frame=void;
       style Header from Header /
             Background=_undef_;
       style Rowheader from Rowheader /
             Background=_undef_;
     end;
   run;

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

   proc print data=sashelp.class;
     title 'line beneath the column headers';
   run;

   ods rtf close;
BACK

RTF2B-How can I remove the all of the grid lines and all of the shading?

To remove the grid lines from within the table, specify the attribute RULES=NONE along with BACKGROUND=_UNDEF_. Issue FRAME=VOID within the style element Table in order to remove the borders from around the table. To remove the shading from the column headers and row headers, add the BACKGROUND=_UNDEF_ attribute in the style elements Header and Rowheader, respectively. View output.

   proc template;
     define style styles.test;
       parent=styles.rtf;
       style Table from output /
             background=_undef_
             Rules=none
             Frame=void;
       style header from header /
             background=_undef_;
       style rowheader from rowheader /
             background=_undef_;
     end;
   run;

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

   proc freq data=sashelp.class;
     title 'removing grids and the shading';
   run;

   ods rtf close;

   
BACK

RTF2C-How can I remove the bold from the row headers after I remove the grid lines?

The font for the row header can be modified in the style element RowHeader. In the example code below, the row header font is changed to that of the cell values. The docFont font is defined in the parent template. View output.

   proc template;
     define style styles.test;
       parent=styles.rtf;
       style Table from output /
             background=_undef_
             Rules=none
             Frame=void;
       style header from header /
             background=_undef_;
       style rowheader from rowheader /
             background=_undef_
             font=fonts('docFont');
     end;
   run;

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

   proc freq data=sashelp.class;
     title 'removing bold font from the row header';
   run;

   ods rtf close;

  
BACK

RTF2D-How can I remove all of the shading and the bolding while maintaining the grid lines?

The shading and the bolding can be removed by applying the style template STYLES.MINIMAL, which is one of the default style templates shipped with SAS; see example 1. This can also be done by using the style template STYLES.RTF and modifying the Style element HeaderAndFooters; see example 2. View output.

   /* Example 1. using  STYLES.MINIMAL  */

   ods rtf body='c:\test\temp.rtf' style=styles.minimal;

   proc print data=sashelp.class;
   run;

   ods rtf close;


   /* Example 2. Modifying STYLES.RTF */

   proc template;
     define style styles.test;
       parent=styles.rtf;
       replace headersandfooters from cell;
     end;
   run;

   ods rtf body='c:\temp.rtf' style=styles.test;

   proc print data=sashelp.class;
   run;

   ods rtf close;
   
BACK

RTF3-Why don't my column headers repeat when my output splits over a new page?

ODS measures tables, titles, and notes horizontally on a page. This allows ODS to break and wrap tables that are too wide for a page. However, ODS does not measure the page vertically. Instead, measuring vertically is turned over to Word, because it positions items like titles and footers unpredictably. When a table splits across a page, Word is responsible for repeating the column headers. The below PROC TABULATE code illustrates this behavior.

   ods rtf file='c:\temp\odsrtf.rtf' ;

   title "this is a title" ;
   data class;
     set sashelp.class;
     do i=0 to 1 by .1;
       age=age+i;
       output;
     end;
   run;

   proc tabulate data=class missing ;
     class sex age ;
     var height weight;
     table sex*(age*all) all ,
     weight height*f=comma8. ;
     Keylabel all='Total' sum=' ';
   run;

   ods rtf close;
    
BACK

RTF4-How can I set the margins for the RTF destination?

You can set the margins of the RTF file by using PROC TEMPLATE and specifying the LEFTMARGIN, RIGHTMARGIN, TOPMARGIN, and BOTTOMMARGIN= attributes. By default, the margins are .25in on all sides.

   proc template;
     define style styles.test;
       parent=styles.rtf;
       style body from document /
             leftmargin=2.5in
             rightmargin=2.5in
             topmargin=2.5in
             bottommargin=2.5in;
       end;
   run;
  
BACK

RTF5-Can I append to an RTF file?

Currently it's not possible to append to an RTF file. This is because an RTF document is composed of orderly parts. As it builds, it stores information for colors, fonts, body, header, and so on. At the close, it puts the different parts in order. Therefore, simply appending is not appropriate for the structure of an RTF document.

BACK

RTF6-Can I prevent the titles and footnotes from being written to the headers and footers of an RTF file?

Starting in Release 8.2, the BODYTITLE option places the titles and footnotes with the output instead of in the header and footer sections of the RTF file.

   ods rtf file='temp.rtf' bodytitle;
   proc print data=sashelp.class;
   run;
   ods rtf close;
    

In Release 8.2, this option does not work correctly when specified with both the NODATE and NONUMBER system options. The workaround is to set the date to the same color as the background. This bug is fixed in SAS 9.

BACK

RTF7-Can I generate landscape output with RTF rather than the default portrait?

Specify the system option ORIENTATION=LANDSCAPE in order to create landscape output with the RTF destination. This option also works with default SAS output.

BACK

RTF8-I specified the fonts "Helvetica" and "Times New" with PROC TEMPLATE but they were not used.

Prior to Release 8.2, some fonts don't get passed from PROC TEMPLATE to Word. This is fixed in Release 8.2.

BACK

RTF9-What device should I use with SAS/GRAPH and ODS RTF?

Prior to Release 8.2, the PNG (Ping) driver is used by default when generating graphs with SAS/GRAPH and ODS RTF. Release 8.2 uses the EMF (Enhanced Metafile) driver by default, but the ACTIVEX driver is also available.

BACK


RTF10-What release of Word gets created by ODS RTF?

Release 8.1 creates Word 97 files, and Release 8.2 creates Word 2000 files.

BACK


RTF11-Can I prevent output created with the RTF destination from going to a new page?

Release 8.2 introduces the STARTPAGE= option, which gives you more control of the pagination in ODS RTF. The STARTPAGE= option values are (YES,ON), (NO,OFF), and NOW.

BACK

RTF12-Can I change the location of the page numbers and the date from the top right corner?

The location of the page number and date can be modified by adding RTF code to the TITLE or FOOTNOTE statement. First issue the system options NONUMBER and NODATE to remove the default page number and date. Example 1, below, right-justifies the date and the page number in the RTF file. Example 2 adds only the page number to the bottom of the page, right-justified. View output.

   /* Example 1 */

   options nonumber nodate;
   ods rtf body='temp.rtf' ;

   proc print data=sashelp.class;
     footnote j=r '{\field{\*\fldinst{\pard\b0\i0\chcbpat8\ql\fc\fs19
              \cf1{DATE \\@ "hh:mm  dddd, MMMM dd, yyyy  " }\cf0\chcbpat0}}}
              {\field{\*\fldinst{\pard\b\chcbpat8\qc\f1\fs19\cf1
              {PAGE }\cf0\chcbpat0}}}';
   run;

   ods rtf close;



   /* Example 2 */

   ods rtf body='temp.rtf' ;

   proc print data=sashelp.class;
     footnote j=r '{\field{\*\fldinst{\pard\b\i0\chcbpat8\qc\f1\fs19\cf1
              {PAGE }\cf0\chcbpat0}}}';
   run;

   /* The below adds the prefix of "Page"  */

   proc print data=sashelp.class;
   footnote1 j=r "{\b\ Page}{\field{\*\fldinst {\b\i PAGE }}}\~
   {\b\i of}\~{\field{\*\fldinst{\b\i NUMPAGES }}}";
   run;

   ods rtf close;
BACK

RTF12A-Can I get my page numbers in page X of Y format?

In SAS 9, the PAGEOF option produces page X of Y numbering with Word 2000. Prior to SAS 9, you can add RTF code in the TITLE or FOOTNOTE statement. Below is an example. View output.

   /* Example 1 */
   ods listing close;
   ods rtf file="temp.rtf";
   proc print data=sashelp.class;
      footnote .j=r " {\b\i PAGE} {\field  {\*\fldinst {\b\i PAGE }}}\~{\b\i
               of}\~{\field{\*\fldinst {\b\i NUMPAGES }}}";
   run;
   ods rtf close;

   /* Example 2 */
   ods listing close;
   ods rtf file="temp.rtf";
   proc print data=sashelp.class;
      footnote j=r "{\field{\*\fldinst {\b\i PAGE }}}\~
               {\b\i of}\~{\field{\*\fldinst{\b\i NUMPAGES }}}";
   run;
   proc print data=sashelp.class;
   run;
   ods rtf close;
BACK

RTF12B-Can I reset my page numbers with RTF? The PAGENO= option doesn't seem to have any effect.

The PAGENO= option does not work with RTF in Releases 8.1 and 8.2. The solution is to insert RTF code to specify the page numbers. The RTF code PGNSTART resets or sets the starting page. Here is an example that sets the first page number at 10.

   ods rtf body='temp.rtf';

   proc print data=sashelp.class;
   footnote j=r '{\field{\*\fldinst{\pard\b\i0\chcbpat8\qc\f1\fs19\pgnstart10\cf1
            {PAGE }\cf0\chcbpat0}}}';
   run;

   ods rtf close;
   
BACK

RTF13- Just when I thought the RTF destination was boring, you add animation.

You can spice up an RTF file by adding the \animtextN control word to the TITLE or FOOTNOTE statement. View output.

   ods rtf body='c:\test\rtf13.rtf';

   proc report data=sashelp.class nowd;
     title '{\animtext1 Hello there}';
     title2 '{\animtext2 How is the weather?}';
     title3 '{\animtext3 I love ODS RTF!}';
     title4 '{\animtext4 This is all for now}';
     title5 '{\animtext5 see ya soon}';
     title6 '{\animtext6 enjoy}';
   run;

   ods rtf close;
    
BACK

RTF14-Can I modify the alignment from always being centered on the decimal?

You can modify the decimal alignment by using RTF code within the PRETEXT= attribute. In the below example, X is trying to force decimal alignment on unruly data. It does this by specifying a style override on the column.

The RTF syntax makes great use of the backslash (\), so the PROTECTSPECIALCHARS instruction is necessary to pass the backslash correctly.

PRETEXT places the RTF code in each cell in the column. The instruction \TQDEC tells the RTF reader to set a decimal tab, and \TX500 specifies to set the decimal tab 500 twips from the left cell border. (A twip is 1/20th of a point and is used in most RTF specifications.) Depending on the shape of the data and the width of the column, you may need to adjust the decimal offset from 500.

   data test;
   x='1.9'; output;
   x='1.91'; output;
   x='1.'; output;
   x='12.'; output;
   run;

   ods rtf file='c:\file.rtf';

   proc print; run;

   proc report data=test nowindows split="|" headline headskip;
     columns x;
     define x / display"Dose 1|(n=457)" width=15
            style(column)=[protectspecialchars=off pretext="\tqdec\tx500 "];
   run;

   ods rtf close;
	
BACK

RTF15-How can I add a superscript or subscript value in my title or footnote?

Superscript and subscript characters can be added by using the ODS ESCAPECHAR= statement in Release 8.2. Below is an example where these characters are added to the TITLE statement.

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

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

   ods rtf close;
      
BACK

RTF16-How can I add images to my RTF file?

Here are two ways you can add images to an RTF file.

  • Beginning with Release 8.2 in ODS RTF, you can add an image before a table with PREIMAGE= and after a table with POSTIMAGE= in PROC TEMPLATE. Below is an example.
       proc template;
         define style styles.test;
           parent=styles.rtf;
           style table from table /
                 preimage='c:\saslog.gif';
         end;
       run;
    
       ods rtf file='temp.rtf' style=styles.test;
    
       proc print data=sashelp.class;
       run;
    
       ods rtf close;
         
  • Beginning with Release 8.2 in ODS RTF, you can add an image to the beginning of the file by using in-line formatting. This is currently a work-around that adds an image into the TITLE1. For subsequent procedures or DATA steps, remove TITLE1 so the image only appears once.
       ods escapechar='^';
       ods rtf file='temp.rtf';
    
       proc print data=sashelp.class;
         title j=l '^S={preimage="C:\V7image.jpg"} ';
       run;
    
       proc print data=sashelp.class;
         title;
         title2 'this is a test';
       run;
    
       ods rtf close;
              
BACK

RTF17-Which style elements and attributes affect the RTF destination?

By default, the RTF destination uses the style template STYLES.RTF, which inherits from STYLES.PRINTER, which in turn inherits from STYLES.DEFAULT. However, not all elements and attributes are used by the RTF destination. See a table that shows which style elements affect the RTF destination.

BACK

RTF18-How can I display RTF output to the browser with SAS/IntrNet?

For information about sending RTF output to an HTML browser by using SAS/IntrNet, see the topic about the APPSRV_HEADER function.

BACK

RTF19-How can I create a table of contents in the RTF destination?

You can create a table of contents in the RTF destination by following the below three steps. View output.

  1. Use the RTF control word \S1 to specify each entry in the table of contents.
       options number nodate;
       /*  bodytitle breaks if you also use both nonumber and nodate  */
    
       ods rtf file='c:\temp\testing456.rtf' bodytitle;
    
       /* The bodytitle option is used to prevent the  */
       /* the title and footnotes from being a part of */
       /* the header and footer sections.              */
    
       ods escapechar='\';
    
       proc print data=sashelp.class;
         title '\R/RTF"\s1 " TESTING 123';
       run;
    
       proc print data=sashelp.class;
         title '\R/RTF"\s1 " TESTING 456';
       run;
    
       ods rtf close;
            
  2. Open the RTF file (here it's testing456.rtf) in a text editor (like Microsoft Notepad). In the RTF file you will find the text below, except you need to add {\s1 Heading 1;} to the string. Save and close the file.
       {\stylesheet{\widctlpar\adjustright\fs20\cgrid\snext0 Normal;}
       {\s1 Heading 1;}{\*\cs10\additive Default Paragraph Font;}
    
  3. Open the saved RTF file in Word and create the table of contents by specifying Insert -> Index and Tables -> Table of Contents -> OK.
BACK

RTF20-How can I generate HTML hyperlinks in the RTF destination?

HTML hyperlinks can be generated with the RTF destination by using the URL= attribute. For example, if you want to add a hyperlink for the column headers, use the URL= attribute directly in the procedures that support the STYLE= option; see example 1. For procedures that don't support this option, use URL= in the template. Example 2 below uses URL= in the CALL DEFINE statement with PROC REPORT to create hyperlinks within the cell values. The hyperlinked cell values show up with the color of blue by default. The below example assumes that the files that are linked are already in existence, with the name of the value used as the naming convention. View output.

   /* Example 1 */

   ods rtf file='temp.rtf';

   proc report data=sales;
     column region state sales;
     define region / order style(header)={url="http:/www.sas.com"};
     define state / order style(header)={url="http:/www.ibm.com"};
     define region / order style(header)={url="http:/www.cisco.com"};

   run;

   ods rtf close;



   /* Example 2 */

   data sales;
     input region $  state $  sales;
     cards;
   East VA 1000
   East DC 2000
   East MD 3000
   East NC 4000
   West CA 5000
   West CA 3000
   West CA 4000
   West AR 3000
   South AL 4000
   South GA 3000
   South TN 2000
   North NY 4000
   ;
   run;

   ods rtf file="temp.rtf" ;

   proc report data=sales nowd;
     column region sales ;
     define region /group width=80  ;
     define sales /sum;
     compute region ;
       href=trim(region)||".html";
       call define(_col_, "URL", href);
     endcomp;
   run;

   ods rtf close;
	

BACK


RTF21-How can I get the correct RTF fonts under an operating environment other than Windows?

With regard to RTF, sometimes you can't find the font you want. In many cases, the Windows font exists as an Adobe font, but the name is slightly different. (SAS uses Adobe fonts under operating environments other than Windows.) In such a case, the easiest fix is to specify the Adobe font name and then post-process the output to get the font name that Word expects. If you are using UNIX (or the UNIX tools on OS/390), you can use the sed command to do this. For example:

   sed < tu.rtf > tu2.rtf -e "s/ITC Zapf Chancery/Zapf Chancery/g" \
      -e "s/New Century Schoolbook/New Century Schbk/g"
BACK

New FAQ (25 November 2002)

RTF22-Why do I get a dialog box in the Results Viewer when I create RTF files?

When you are generating RTF files with ODS, and you get a dialog box in the Results Viewer and no RTF file rendered in Word, then either you do not have MS Word or the Word Viewer installed, or, if you have one of these installed, then you need to associate the RTF file extension to Word.

To register the .RTF extension to Word, follow these steps: On your Windows machine, open a folder and find an RTF file. With your mouse cursor over the file, press the the right mouse button, select Open With, select Choose Program, select Microsoft Word, and select the Always use this program to open these files check box. Your Windows registry will be updated.

BACK


New FAQ (25 November 2002)

RTF23-How can I add special characters such as LE or GE to my RTF output?

You can add special characters such as the GE or the LE symbols to your RTF output by using the appropriate fonts that have these symbols. For instance, GE and the LE characters are available in the symbol font. Below is an example of specifying this in your output. For a list of the hexadecimal values of commonly used special characters, see the URL http://www.bbsinc.com/iso8859.html.

   ods escapechar="^";

   proc format;
      value temp 11='The value is ^S={font_face=symbol}' "A3"x '^S={} the value';
   run;

   ods rtf file='temp.rtf';

   proc print data=sashelp.class;
      title 'This uses the special characters in the value';
      format age temp.;
   run;

   proc print data=sashelp.class label;
      title 'This uses the special characters in the label';
      label age="Age" "^S={font_face=symbol}" "B3"x "^S={}" "10";
   run;

   ods rtf close;
BACK

New FAQ (25 November 2002)

RTF24-Why am I still getting gray lines after removing all of the borders from the table?

The light gray lines only display when viewed and not when printed. To make them disappear or appear, in Word change the Gridlines option under the Table menu.

BACK


New FAQ (25 November 2002)

RTF25-How can I create RTF output that looks exactly like my listing output?

ODS generates tabular output. Therefore, there is no direct way to make the ODS RTF output look like the SAS listing output. Here are a couple of indirect ways. The example below uses PROC PRINTTO to save the output to a flat file and then uses a DATA step to read the output back in. The only problem with this approach is that the page-eject characters are simply ignored by RTF. This is because RTF has its own control words that generate page breaks or section breaks.

A better method is to use a macro created and contributed by David Ward. The macro saves the output to an external file, but unlike the below example, it looks for the page breaks in the listing and changes the values to RTF control characters that specify page breaks. The macro allows some other options to be specified as well; see the @out2rtf macro.

   proc printto file='c:\temp\tmp.lst';

   proc print data=sashelp.class;
      title 'get listing look in rtf';
   run;

   proc printto;
   run;

   ods rtf file='c:\temp\monospace.rtf';
      title 'Listing look in RTF';
         options nodate nonumber;
   data _null_;
   infile 'c:\temp\tmp.lst' length=lg;
   input @1 line $varying400. lg;
   file print;
   put @1 line $varying. lg;
   run;

   ods rtf close;
BACK

New FAQ (June 2003)

RTF26-Can I prevent my titles from disappearing when using the STARTPAGE=NO option?

When the STARTPAGE=NO option is specified, the default is to remove the titles and footnotes. There is no way currently supported to make them appear, other than restoring the option to the default of STARTPAGE=YES. However, you can use the experimental TEXT= option, which writes out text before the table. In Release 8.2, this option does not support styles, and therefore it is left justified and has a default font. The good news is that you can supply the style information using the RTF control words. Below is an example using the TEXT= option. The title is centered and has a font size of 20pt, which is specified with the \fs40 control for RTF.

   ods rtf file="test.rtf" startpage=no;
   ods rtf text="{\trowd\trqc\cellx11520\fs40\intbl\qc{This is a test\cell}{\row}\pard}";

   proc print data=sashelp.class;
   run;

   ods rtf text="{\trowd\trqc\cellx11520\fs40\intbl\qc{This is a second test\cell}
                  {\row}\pard}";
   proc print data=sashelp.class;
   run;

   ods rtf close;

BACK








Search | Contact Us | Terms of Use & Legal Information | Privacy Statement
Copyright © 2003 SAS Institute Inc. All Rights Reserved.