Sure, you have a great looking table and you produce it with PROC TABULATE. And then, bam! Your boss comes along and decides that since your output looks so good in Word, that he’d like that boilerplate paragraph inserted automatically. Currently, you produce the tables and then pass the RTF files off to a colleague who cuts and pastes the boilerplate text into the document and then resaves the document, but life would be so much easier for everyone if your program could do this automatically. Your boss wants to know if this is possible. And, you want to know, if it’s possible, how?
ODS TEXT to the rescue! The purpose of the ODS TEXT statement is to write text to all open ODS destinations. Your perfectly good PROC TABULATE step looks like this:
Figure 1: Perfectly Good PROC TABULATE Output
The boilerplate text is just a standard disclaimer or maybe it changes for every customer. For illustration purposes, this boilerplate text will be read with a DATA step program:
data boilerplate; length line $100 caption1 caption2 $4000; retain caption1 ' ' caption2 ' '; infile datalines dsd; input capnum line $; if capnum = 1 then caption1 = catx(' ',caption1,line); else caption2 = catx(' ',caption2,line); call symputx('caption1',caption1); call symputx('caption2',caption2); return; datalines4; 1,"xxxxxxxxx yyyyyyyyy zzzzzzzzz" . . . more text for Caption 1 . . . 2,"aaaaa bbbbbbb ccccccc ddddddd eeeee" . . . more text for Caption 2 . . . ;;;; run; %put &caption1; %put &caption2;
The results of the %PUT statements are shown in the SAS Log:
Figure 2: Caption Text Displayed in SAS Log
So now, the captions can be used in the TABULATE program. Here is the revised code:
ods rtf file='c:\temp\caption_program.rtf' startpage=no; ods text="&caption1"; proc tabulate data=shoes f=comma10.; run; title; ods text="&caption2"; proc tabulate data=shoes f=comma10.; run; ods rtf close;
And here is the output created from that code:
Figure 3: TABULATE Output With Captions
Of course, instead of using a DATA step program and Macro variables, the captions could have been typed into the ODS TEXT statements, but this method would also allow you to change the text programmatically, if you needed to.
ODS TEXT= is one of the ODS options that is covered in our SAS Report Writing 1: Essentials class, along with more details on PROC TABULATE, PROC REPORT and ODS STYLE= options. So now, you know how to add absolutely frabjous captions to your tables and report output.
The full code is available here.