Stat-Tech Services, LLC
Macro Reporting System Help Guide
How to use the RTF System
RTF System
The RTF print system is a system of macros for printing Rich Text Format (RTF) files. Rich Text Format is a mark-up language for saving word processed files. RTF files can be read and created by most major word processing programs. Word processed files have many features that have not historically been available to SAS programmers: mixing of fonts, mixing font sizes, text formatting (italics, bolding, underlining), and table creation.The authors are aware of several attempts to generate RTF using SASÒ /Macros. We chose to follow our own approach because we wanted a system that would fit into our Macro Reporting System (MRS).
The RTF print system is intended to handle a great deal of the programming work required to generate RTF output. The information required to generate an output is similar to that needed for a PROC REPORT listing. Since the RTF system handles multiple fonts, font sizes, and text formatting, there are additional options included. However, the RTF system does not require the user to write a DATA _NULL_ or otherwise know much about RTF commands.
The RTF Macros are designed as a system. Most of the macros use %GLOBAL commands to pass information between macros in the system. The following pseudo-code outlines the specification of an RTF listing:%RTFINIT(data=… initializes the RTF system and specifies various global parameters: fonts, continuation messages, and a pagination variable.)
%RTFCOL(var=… adds a column to the listing and specifies the variable, format, label, type (BY or DISPLAY), and width of the column (inches). Columns appear in output in the same as the RTFCOL calls are ordered in the program.)
%RTFSPAN(text=… adds a column spanning header to the output. Spanning headers cover the columns specified by subsequent RTFCOL calls. Standard text formatting for headers and the body of the output are specified in RTFINIT.)
%RTFCOL(var=… this column would be covered by the previous spanning header.)
%RTFSPEND terminates the most recent spanning header. This macro has no parameters. NOTE: Spanning headers can be nested.
%RTFTITLE(text=… specifies a title for the output along with formatting options. All titles and footnotes have three regions: left justified text, centered text, and right justified text. Users can specify text for all of these regions. Titles, tails, and footnotes appear in the order they are specified.)
%RTFFOOT(text=… specifies a footnote).
%RTFTAILl(text= specifies a tail footnote (our lingo for a footnote attached to the bottom of a table). Tails operate like footnote, but only have one region with can be left, right, or center justified.)
%RTF uses the compiled information to write a data _null_ that generates the RTF output file.
In this context one can consider the RTFINIT call to be similar to a SASâ PROC call that initializes the RTF procedure. The middle macros specify the content and appearance of the output. The RTF call processes the information.
RTF versus the MRS PRINT System
The RTF print system follows the same syntax order as the MRS print system. All of the standard MRS print system have corresponding RTF macros, e.g. COLUMN is replaced by RTFCOL. A few differences to keep in mind are:Using RTF with the MRS Table Generation System The RTF macros have been integrated with into the MRS table generation system. There are three RTF replacements to the standard library of MRS macros:Column widths in RTF specify 1/10ths of inches, while column widths in the MRS print system consist of actual character spaces.
The RTF print system requires the user control the page size with TABLINES= in the RTFINIT macro. The MRS print system automatically calculates page size.
Actual page type (PORT versus LANDSCAPE) and actual page margins in 1/10ths of inches are set within the RTF system.
The RTF print system usually requires additional specification of font and font size information.
In the RTF system, the lines are generated with borders (like in word processed tables) as opposed to the MRS print system lines that are line characters. This means that lines will not always be evenly spaced between the text.
RTFASMBL replaces the ASSEMBLE macro for use in table generation.
RTFTTLGN replaces the TITLGEN macro for handling titles/footnotes.
RTFPAGE replaces the PAGEIT macro for adding pagination information to RTF output (e.g. Page X of Y).
In addition, there are several macro parameters were added to ITAB used in table generation.
Special Issues Font Tables Different fonts can be identified for various parts of the RTF output. Fonts are referenced by numbers (1-5) and refer to the fonts specified in the RTFINIT call. E.g. %RTFTITLE(..,font=3,…) assigns font #3 to the given title. Three default fonts are already specified in RTFINIT: 1 = SAS Monospace, 2 = New Times Roman, 3 = Arial, and 4 = Symbol.Font sizes are not specified in conjunction with font types. Font sizes for the column headers and the body of output are specified in RTFINIT. Titles, tails, and footnotes may have their own font sizes.
Text Formatting
The following formatting options are built into the RTF macros. For titles, tails, and footnotes, the user can turn on bold, italics, and/or underline for the entire line via the RTFTITLE, RTFTAIL, and RTFFOOT calls, respectively. Text formatting for the header region of the output (spanning headers and column labels) can be set to bold, italics, and/or underline through the RTFINIT call.The font number and font size for titles, tails, and footnotes can be set for each individual line with the respective macro call.. The font number and font size for all the columns and all the body text are set in the RTFINIT call.
The user can further customize text in the table by using standard RTF commands within labels, titles, etc. See the TEST002.SAS example where a superscript is created in a column label and in a tail footnote. A complete RTF reference guide may be downloaded from various locations on the WWW (http://night.primate.wisc.edu/software/RTF/). Also see the end of this document for a table of text formatting commands.
SAS Quoting Functions
It may be necessary to use %STR and %BQUOTE to properly specify text in labels, titles, etc. It is highly recommended that users become familiar with these functions. Pagination Issues This version of the RTF Macro System is not entirely robust with respect to pagination. Users may have to adjust the TABLINES= option to ensure the output fits on a single page. RTF Macro Descriptions This section describes the instructions for each macro in the RTF Macro SystemThis macro must be called first when specifying an output.
| Parameter | Default | Description |
| DATA= | (Required) Data set to print | |
| FILENAME= | tmp.rtf | Name of RTF file to be create |
| TABLINES= | 10 | Maximum number of lines to print in the body |
| HEADSKIP= | Y | Causes system to insert a blank line after the headers. |
| BODYFONT= | 3 | Font specification for body |
| BODYSIZE= | 10 | |
| LABFONT= | 3 | Font specification for column headers and spanning headers |
| LABSIZE= | 10 | |
| LABBOLD= | Y | (Y or N) Bold |
| LABITAL= | N | (Y or N) Italics |
| LABUNDER= | N | (Y or N) Underline |
| STYLE= | LINES | Output Stye:
LINE = lines at bottom and top of table OUTLINE = line around outside of table BOX = tabulate style lines. LINEX is a variation of LINE which puts a separator line between BY and LINE= levels of the output. LINEXB does the same as LINEX but also inserts a blank line. |
| PAGE= | Pagination variable (appears after title) | |
| PAGELBL= | Label for pagination variable | |
| PAGEFMT= | Format for pagination variable | |
| SHOWPAGE= | Y | (Y/N) Show or suppress printing of pagination variable. |
| CONTMSG= | Used to specify a continued text message that
appears at the bottom of the body of output if it is not the EOF. E.g.
contmsg = %bquote((continued))
Ignored if null. | |
| CONTJST= | L | Justification of continued message (L,C,R,S) S is a special type of continued message that shows up at the right side of the last TAIL footnote, must be shorter than 1.5 inches. |
| CONTLP= | N | Use Y to make continued message appear on last page. |
| TOPMSG= | Used to specify a continued text message above the column labels/ spanning headers of the output. Appears on all but the first page. | |
| TOPJST= | L | Justification of top continued message. Valid values are L, R, C and T#. T# adds the messages to the end of the title line. |
| TOPFP | N | Use Y to make top continued message appear on first page. |
| LINE= | Line variable. Such a variable is used to add spaces in the output but is not printed. | |
| SPLIT=* | Parsing value to column labels. | |
| TITLE= | Information fields for document (not related to printing). | |
| AUTHOR= | ||
| COMPANY= | ||
| COMMENT= | ||
| PAPER= | STAND | Accepts LEGAL to produce Legal size (8.5"x14") paper documents. |
| LAND= | Y | Y = Landscape, Blank = default |
| TOPM= | 10 | Top margin in 10ths of an inch. |
| BOTTOM | 10 | Bottom margin in 10ths of an inch. |
| RIGHTM= | 10 | Right margin in 10ths of an inch. |
| LEFTM | 10 | Left margin in 10ths of an inch. |
| FONT1 | SAS Monospace | Font Table information |
| FAMILY1 | fmodern | |
| FONT2 | New Times Roman | |
| FAMILY2 | froman | |
| FONT3 | Arial | |
| FAMILY3 | fswiss | |
| FONT4 | Symbol | |
| FAMILY4 | ftech |
This macro adds columns to the output. Columns appear in the order of the RTFCOL calls.
| Parameter | Default | Description |
| VAR= | Variable name | |
| FMT= | Format for variable | |
| LABEL= | Label for column | |
| JUST= | C | Justification (C,R, D, or L). Note - D is decimal tab centered and is intended to be used with numeric formats. |
| WIDTH= | 10 | Width of column in 10ths of inches |
| TYPE= | null or BY - BY variables are used for sorting and are printed only on FIRST. Conditions | |
| HANG= | 0 | Hanging indent for wrapped cells in 10ths of inches. |
| CONTEXT= | (Continued) | Text to be added to by-group value at the top of preceding pages where by group spans two or more pages.ths of inches. |
| USECONT= | Y | Switch to control when CONTEXT is displayed.ths of inches. |
RTFSPAN
The macro specifies spanning headers. The starting column and height of the spanning header is determined by is order relative to RTFCOL calls. Multiple spanning headers are allowed..
| Parameter | Default | Description |
| TEXT= | Text of spanning header (USE %BQUOTE LIBERALLY). | |
| JUST= | C | Justification of spanning header (C, R, or L) |
RTFSPEND
This macro lets the system know that the last preceding unclosed spanning header should be closed.RTFSPEND has no parameters.
RTFTITLE
Title specification macro. Titles appear in the order they are specified. Note, there are three possible regions of header text and they can all appear on the same line (right, centered, and left justified text). Blank titles may be created with a call of %RTFTITLE(TEXT=%STR( ))
| Parameter | Default | Description |
| TEXT=, LTEXT=, RTEXT= | Text of title (USE %BQUOTE LIBERALLY). These specify the centered, left, and right justified text to appear in a header (title) | |
| LMARG=, RMARG= | 15 for both | Amount of space in 10ths of inches to allow for right and left justified header text. |
| FONTNUM= | 3 | Font number |
| FONTSIZE= | 10 | |
| BOLD= | N | |
| UNDER= | N | |
| ITALICS= | N |
RTFTAIL
Tail footnote specification macro. Footnotes appear in the order they are specified.
| Parameter | Default | Description | ||
| TEXT= | Text of tail footnote (USE %BQUOTE LIBERALLY). | |||
| JUST= | L | Justification of spanning header (C, R, or L) | ||
| FONTNUM= | 3 | Font number | ||
| FONTSIZE= | 10 | |||
| BOLD= | N | |||
| UNDER= | N | |||
| ITALICS= | N | |||
RTFFOOT
Footnote specification macro. Footnotes appear in the order they are specified.
| Parameter | Default | Description |
| TEXT=, LTEXT=, RTEXT= | Text of footnote (USE %BQUOTE LIBERALLY). These specify centered, left, and right justified text to appear in the header. | |
| LMARG=, RMARG= | 15 for both | Amount of space in 10ths of inches to allow for right and left justified header text. |
| FONTNUM= | 3 | Font number |
| FONTSIZE= | 10 | |
| BOLD= | N | |
| UNDER= | N | |
| ITALICS= | N |
RTF
The RTF macro is called to generate the output file. It has no parameters.
RTF Text Formatting Commands
This section describes a few of the RTF text formatting commands that can be used to modify the appearance of text in RTF output. Remember to leave a blank space after the formatting command.
Text Formatting
The user can turn on/off bolding, italics, and underlines within a text string. The formatting must be turned on and off in the label. These formatting commands are additive. Failure to turn off formatting will cause it to be applied to all subsequent text.
| Formatting |
Start Command |
End Command |
| bold
italicized underline outline small caps all caps shadow strikethrough hidden text |
\b \i \ul \outl \scaps \caps \shad \strike \v |
\b0 \i0 \ul0 \outl0 \scaps0 \caps0 \shad0 \strike0 \v0 |
Example 1:
The following title would have Important as bold.
%rtftitle(text=This is an \b Important\b0 table)
Example 2:
The following format would have Active italicized in RTF output.
proc format ;value grp 1 = ‘Placebo’
2 = ‘\i Active\i0’
;run ;
Superscripts and Subscripts
Individual text can be modified to be a subscript or superscript. Subscript and superscript move the text down or up and shrink the font size. Text can be moved up or down with the up and down commands, but the font size is not changed.
| Formatting |
Start Command |
End Command |
| Subscript
Superscript Up Down |
\sub \super \upN \dnN |
\nosupersub \nosupersub \dn \up |
Here N is the distance moved in half-points (default is 6).
Example:
The following column label contains a superscripted 1 related to a footnote note.
%rtfcol(var=risk,label=%bquote(Risk Group \super 1\nosupersub),fmt=risk.)
Fonts and Font Sizes
Fonts may be changed within text by referring to the font table. Font sizes may be changed as well with the number being ½ point sizes. (e.g. to get point size 10, specify font size of 20). Fonts and font sizes remained changed until set to another font type or size.
| Formatting |
Start Command |
End Command |
| New Font
New Font Size |
\fN \fsN |
na na |
Example:
The following puts the character a into the text then turns the font back to Arial.
%rtffoot(text=%bquote(The overall \f4 a\f3 -level was 0.05))
Paragraph Formatting and Tabbing
The user can add custom indention, paragraph returns, and tabs within the text.
RTF Replacement Macros for the MRS
NOTE: With the exception of PREVIEW and _QTSLASH, these macros are only distributed with the MRS.
The following macros follow the syntax specified in the MRS, with the some changes. The macros are discussed separately.
ITAB
Two new parameters were added to the MRS macro ITAB. These parameters provide control over the width of table columns
| Parameter | Default | Description |
| VWTWIPS= | 15 | Controls width of variable column when using RTF print system. Column width is measured in tenths of an inch. This setting is independent of VWIDTH however vwidth will influence the appearance of Variable label and value label text. If the vwidth setting is too small rtfasmbl will parse variable column text and place line breaks in inappropriate places. |
| CWTWIPS= | 10 | Controls width of the column under groups and subgroups when using RTF print system. Column width is measured in tenths of an inch. |
RTFASMBL
This macro serves the identical purpose of ASSEMBLE in MRS. However instead of ASCII tables RTFASMBL coordinates the RTF print system to produce tables in RTF format. It has many of the parameters of RTFINIT. It also has some of the parameters found in the original ASSEMBLE.
| Parameter | Default | Description |
| FILENAME= | Name of RTF file to be create | |
| TABLINES= | 40 | Maximum number of lines to print in the body |
| BODYFONT= | 3 | Font specification for body |
| BODYSIZE= | 10 | |
| LABELIND= | 2.5 | Default label indent in tenths of inches. |
| LABFONT= | 3 | Font specification for headers |
| LABSIZE= | 10 | |
| LABBOLD= | N | (Y or N) Bold |
| LABITAL= | N | (Y or N) Italics |
| STYLE= | LINES | Output Stye:
LINE = lines at bottom and top of table OUTLINE = line around outside of table BOX = tabulate style lines |
| CONTMSG= | (Continued) | Used to specify a continued text message that
appears at the bottom of the body of output if it is not the EOF. E.g.
contmsg = %bquote((continued))
Ignored if null. |
| CONTJST= | S | Justification of continued message (L,C,R) |
| CONTLP= | N | Use Y to make continued message appear on last page. |
| TOPMSG= | \b0 (Continued)\b | Used to specify a continued text message above the column labels/ spanning headers of the output. Appears on all but the first page. Note the inclusion of RTF code to turn Bold off before (Continued) and back on after. |
| TOPJST= | T1 | Justification of top continued message. |
| TOPFP | N | Use Y to make top continued message appear on first page. |
| LINE= | _morder | Line variable. Such a variable is used to add spaces in the output but is not printed. |
| LAND= | Y | Y = Landscape, Blank = default |
| TOPM= | 15 | Top margin in 10ths of an inch. |
| BOTTOM | 10 | Bottom margin in 10ths of an inch. |
| RIGHTM= | 10 | Right margin in 10ths of an inch. |
| LEFTM | 12.5 | Left margin in 10ths of an inch. |
| ADDSET#= | Specifies a data set containing an additional column to appear in the output after the group/subgroup and total columns. Up to 5 columns may be specified. E.g. # = 1, 2, 3, 4, or 5. | |
| ADDLAB#= | Specifies the label to appear above the additional column number #. |
SPECSPAN
This macro is a special spanning header that can be used in place of the default group label spanning header. This macro provides an alternative method to place a spanning header at the top of an MRS table. It will only manifest if there is no group label. All parameters are identical to the parameters of the rtfspan except start and stop. Start is the column number the spanning header starts at and stop is the column the header ends at. Counting starts with 1=the first group column. The variable column is not counted for purposes of locating the special spanning headers.
| Parameter | Default | Description |
| TEXT= | text of spanning header | |
| JUST= | c | Justification |
| START= | Start Column | |
| STOP= | Stop Column |
RTFTTLGN
This macro runs the title subsystem for the RTF macros. The title data base is identical to the MRS title data base except for a new footnote type (A file attached) and the ability to add RTF commands to the title text to precisely modify text properties.
| Parameter | Default | Description |
| PROGNAME | Program reference for the title | |
| REF | Reference code within the progname for the actual title. | |
| PRINTTO= | OFF | (or ON) tells whether to issue a proc printto
command
mapping the output to the designated file. PRINTTO=ON creates a global variable with the program name stored. |
| FILEDEST= | Used to specify the directory for the output
file to run.
Example: filedest=\project\sasout (not \project\sasout\) | |
| TITLFILE= | TITLE.TXT | text file containing title information |
| TFONT= | 3 | Title font number (see documentation for rtfinit). |
| TFSIZE= | 12 | Title font size. |
| TLMARG= | 15 | Size, in tenths of an inch, of the left field in the three title line (allows multiple justifications in a single title line). |
| TRMARG= | 15 | Size, in tenths of an inch, of the right field in the three field title line. |
| FFONT= | 3 | Footnote font number. |
| FFSIZE= | 10 | Footnote font size. |
| FLMARG= | 15 | Size, in tenths of an inch, of the left field in the three field |
| FRMARG= | 15 | Size, in tenths of an inch, of the right field in the three field footnote line. |
_QTSLASH
This macro quotes backslash character so it will be correctly interpreted by rtf engine. It is a function type macro.
| Parameter | Default | Description |
| INVAR= | Input text string variable containing backslash to be quoted for inclusion in RTF document text. |
This is a utility macro.
PREVIEW
This macro opens the RTF document in MS-Word from the program run using DDE calls.
| Parameter | Default | Description |
| Show= | N | Flag to send rtf file to MSWord |
| FILENAME | Name of file to be opened in MSWord. This macro has been adapted to work with the MRS-RTF Title subsystem. If this parameter is left empty and rtfttlgn is used, then the global macro variable printfil will be used to identify the RTF file to be opened. |
RTFPAGE
RTFPAGE is a modification of PAGEIT with a reduced set of parameters. The following PAGEIT parameters are still present: FILE=, TARGET=, and STYLE=. The PP= and J= parameters are not applicable with the RTF print system.