BookmarkSubscribeRSS Feed
Snow_Belssas
Calcite | Level 5
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.

SSAS
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
Hi:
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:
[pre]
ods rtf file='alltogether.rtf';
** proc 1;
** proc 2;
** proc 3;
ods rtf close;
[/pre]

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.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2769 views
  • 0 likes
  • 3 in conversation