The SAS Output Delivery System and reporting techniques

Merge RTF files into one

Occasional Contributor
Posts: 10

Merge RTF files into one

Dear SAS experts

Could any of you show me some tips or program codes which can merge rtf files (from ODS RTF) into one single RTF file. Many thanks in advance.

Super Contributor
Super Contributor
Posts: 3,174

Re: Merge RTF files into one

You may want to start out by inspecting an RTF file - then ask the question (of yourself): do I really want to parse an RTF file? If the answer is yes, then you would likely have a SAS DATA step to INPUT, SCAN, SUBSTR, and do other nasty things to inhale/digest the RTF file, capturing important (to you) pieces of information. Then do the same to some other RTF file. Then sort the two files. Then use SAS DATA step with a MERGE. Then output a new RTF file in the Microsoft-standard defined format.

Good luck.

Scott Barry
SBBWorks, Inc.
Posts: 8,743

Re: Merge RTF files into one

When you use an ODS RTF "sandwich", you can have any number of procedure or data steps and ALL the outputs will go into 1 RTF file:
ods rtf file='alltogether.rtf';
** proc 1;
** proc 2;
** proc 3;
ods rtf close;

However, an RTF file has "top of file" control strings and "bottom of file" control strings. So once the RTF file has been created, the only way to combine files is to open the RTF file in a word processor and insert files together using word processor methods. Then, the file must be resaved, either as a .DOC file or as a new .RTF file.

Or, once the RTF files have been created by SAS, you could "post process" the RTF files and strip the closing control strings from one file and then strip the opening strings from the other file, put the two files together. Then assuming that you haven't corrupted the RTF control strings, you would have essentially combined the two files together. However, in my experience with post processing RTF files, I have found the RTF strings to be very "touchy" and a single misplaced or mismatched '{' can cause the RTF file to be unopenable.

There is, also, the whole world of VB scripts or Word macros for opening and combining files and then resaving the files.

Finally, if by "merge" you mean to take a table from one RTF file and treat it as data to merge with a table from another RTF file, I find myself wondering whether the underlying data or tables that created the original RTF files are still available for merging. That would be much easier to deal with than trying to extract the data tables from the RTF files.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation