PROC TEMPLATE FAQ and Concepts
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. BACK
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
- JUST=
- 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 Just=l "this title is left justified";
title3 link="www.sas.com" "this is my hyperlink";
BACK
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. BACK
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;
BACK
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;
BACK
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;
BACK
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;
BACK
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:
- locally, an option on the TITLE or FOOTNOTE statement
- an option on the GOPTIONS statement (such as FTEXT)
- 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;
BACK
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. BACK
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 body /
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. In Release 8.2, this option does not work
correctly when specified with both the NODATE and NONUMBER system
options. ods rtf file='temp.rtf' bodytitle;
proc print data=sashelp.class;
run;
ods rtf close;
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;
ods rtf close;
BACK
RTF12A-Can I get my page numbers in page X of Y format?
In Version 9, the PAGEOF option produces page X of Y numbering
with Word 2000. Prior to Version 9, you can add RTF code in the
TITLE or FOOTNOTE statement. Below is an example. View output.
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.
- 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;
- 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;}
- 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
New FAQ (31 May 2002)
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
|