The SAS Output Delivery System and reporting techniques

TOC creation in ODS RTF

Reply
Contributor
Posts: 60

TOC creation in ODS RTF

Hi,

I have RTF output created by SAS ODS, Is there any way to append all the RTF outputs and Create a Table Of Content for this appended document.

Thanks
Sudhakar
SAS Super FREQ
Posts: 8,640

Re: TOC creation in ODS RTF

Hi:
If you put all your steps into 1 ODS RTF "sandwich", then all the tables would be together in one RTF document -- with 1 table of contents. Something along these lines:

[pre]
ods rtf file='somefile.rtf' contents=yes toc_data;
*** proc or data step 1;

*** proc or data step 2;

*** proc or data step 3;
run;
ods rtf close;
[/pre]

As explained in this Tech Support note
http://support.sas.com/kb/24/034.html
you cannot append RTF files together using SAS.

The only ways to assemble multiple RTF files together are:
1) put all your SAS code within one ODS RTF "sandwich" -- so that the parts/sections of your document are built by SAS from multiple procedures.
2) assemble your multiple RTF files in Microsoft Word or some other Word processor (possibly using VBScript or a Word macro)
3) post-process the RTF files with a program to selectively remove the RTF control characters that define either the beginning or end of a file.

There have been other forum postings on this topic:
http://support.sas.com/forums/thread.jspa?messageID=5513ᖉ
http://support.sas.com/forums/thread.jspa?messageID=6434ᤢ
http://support.sas.com/forums/thread.jspa?messageID=14026㛊

cynthia
Contributor
Posts: 60

Re: TOC creation in ODS RTF

Thank you very much. I will explain my situation

1. Output1.rtf generated by User1
2. Output2.rtf generated by user2

So One output is independent of each other so after all the outputs are generated we have to append these outputs and also to create a TOC

Thanks in advance
SAS Super FREQ
Posts: 8,640

Re: TOC creation in ODS RTF

Hi:
So, the #1 workaround, as explained above will not work for you. That leaves only #2 (do something in Word to assemble the files and build the TOC) or #3 post-process the RTF file with a program.

Your only other alternative (depending on what procedures you are using for each report table) might be to create an ODS DOCUMENT store and then assemble the final document using ODS DOCUMENT and PROC DOCUMENT statements. But that means you would create the ODS DOCUMENT store -instead of- the RTF files from user1 and user2. Then your final RTF file would be built from these document objects, not from existing RTF files. For an overview of ODS DOCUMENT capabilities, refer to these papers or the ODS DOCUMENT documentation:
http://support.sas.com/resources/papers/sgf09/318-2009.pdf
http://www.lexjansen.com/wuss/2003/DataPresentation/i-peek_at_proc_document.pdf

cynthia
Contributor
Posts: 60

Re: TOC creation in ODS RTF

Hi,

It was a good idea to make this happen, i read this document and when i was trying to use this i got the warning "WARNING: PROC REPORT does not support the ODS Document in this release."

Thanks for the help.

Sudhakar
Grand Advisor
Posts: 9,679

Re: TOC creation in ODS RTF

I think the way to generate your TOC from separately created RTF would be by using the RTF field codes using RTF TEXT.

Place this code in document portion and position that you want the TOC to appear:
ODS RTF TEXT="{\field{\*\fldinst {\\TOC \\f \\h} } }";
to insert the field code for a table of contents that will also create hyperlinks to the entries.

Before each item in your report insert at table of contents entry code using:
ods rtf text= " {\tc \tcl }";

The is used to create indent levels when desired, use 2 or greater such as \tcl2. If you just have \tc then all items will be at the main level of the TOC.

Style elements can be used to modify the text by placing the style descriptors before the {. The text will also appear in the body of your document using the styles but the TOC settings for the document will control appearance in the TOC.

After all of the document sections are merged, I assume using Word, then find the TOC field and do the Update all entries to display the table. I found it a bit difficult to find the field as there isn't anything visible but if you place it on an empty page near the start of the document you should be okay.

Note that this does not use any of the SAS procedure TOC entry behaviors so individual tables to not get entries, just what you supply.

DO NOT use the highlight all and menu item to insert a table of contents as you will create a separate TOC entry.

I hope this helps.
Contributor
Posts: 60

Re: TOC creation in ODS RTF

Hi,

Thank you vey much its seems this idea will work i will try this way.

Thank once again for all.

sudhakar
Grand Advisor
Posts: 9,679

Re: TOC creation in ODS RTF

I forgot to mention that you will need to use a style that has PROTECTSPECIALCHARACTERS=OFF set.

I believe this is mentioned in http://support.sas.com/resources/papers/sgf09/318-2009.pdf
SAS Super FREQ
Posts: 8,640

Re: TOC creation in ODS RTF

Hi:
I don't remember PROTECTSPECIALCHARS in that paper! But look on page 8 of this paper:
http://www.nesug.org/proceedings/nesug06/io/io13.pdf

...it talks about all the various methods of creating and customizing a Table of Contents specifically for the RTF destination.

cynthia
Frequent Contributor
Posts: 112

Re: TOC creation in ODS RTF

I kept getting an error that Word could not understand my formatting. I realized that it is "\TCL" and not "TC1" after nearly pulling my hair out.

Tricia Aanderud
Zencos Consulting
Twitter: @taanderud - Follow me!

Post a Question
Discussion Stats
  • 9 replies
  • 482 views
  • 0 likes
  • 4 in conversation