BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Everyone!
I was wondering if there was a way to add a table or graph to an existing text document. For example, if we have a Word document containing specific text, I would like to add table output from PROC REPORT or a graph to the text, and write the result out to a single RTF document.

If this is possible, are there ways to control where the insertion of the table or graph occurs?

Thanks in advance!!

-Phil
7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
It is much easier to append a new HTML file to an existing HTML file, than it is to append a new RTF or PDF file to an existing RTF or PDF file.

See these Tech Support notes:
http://support.sas.com/kb/24/034.html
http://support.sas.com/kb/23/660.html

The info about the RTF file also applies to PDF. Basically, both RTF and PDF have a very stringent (not flexible) syntax for the way they want the file open and file close to be specified.

You might consider writing a little VB script for Word that opens the first RTF file, brings in or inserts the second RTF file and then resaves the "new" document over the first file name. There might be 3rd party software that allows you append 2 RTF files together -- I'm betting they strip out the file close from the first file and the file open from the second file to make it work. I suppose you could also write a DATA step program to post process the 2 files and do the same thing, but the few times that I've messed with post-processing RTF, I've generated a corrupted RTF file too easily. RTF is hard to figure out and 1 wrong curly brace or \ and bam, you've corrupted the RTF file and Word won't open it.

Of course, one simple technique might be to save your original output objects (if possible) in an ODS Document store and then when you need to add information, you could replay the first document's output objects with the new output objects and make a new RTF file or write over the old name.

Another thing you could do is use ODS RTF TEXT= to insert big blocks of text around your table and/or graph. This is sort of doing the reverse that you asked about -- you would be taking the text from the first document and would add it to the new document.

An example of using ODS RTF TEXT= is shown below.

cynthia
[pre]
data _null_;
length bigtext $2000 line $100;
retain bigtext;

infile datalines dsd dlm=',';
input lineno line $ ;
bigtext = catx(' ',bigtext,line);

** can not use end= with datalines, so use lineno var;
** to create macro variable at end of poem.;
if lineno = 8 then do;
call symput('jabber',trim(bigtext));
end;
return;
datalines;
1,"Twas brillig and the slithy toves,"
2,"Did gyre and gimble in the wabe."
3,"All mimsy were the borogroves."
4,"And the mome raths outgrabe."
5,"Beware the Jabberwock, my son!"
6,"The jaws that bite, the claws that snatch."
7,"Beware the Jubjub bird and shun"
8,"The frumious Bandersnatch!"
;
run;

%put ---------> &jabber;

ods listing close;

options orientation=portrait center;
ods rtf file='c:\temp\addtext.rtf' startpage=no nokeepn;
ods escapechar='^';

title 'What This Report Needs Is Some Jabberwocky';

ods rtf text="^S={font_style=italic font_weight=bold just=l}&jabber &jabber &jabber";

proc print data=sashelp.class;
run;

ods rtf text="^S={foreground=red font_face=Arial font_size=10pt just=l}&jabber &jabber";

proc print data=sashelp.class;
run;

ods rtf text="^S={foreground=green font_face=Arial font_size=10pt just=l}&jabber &jabber";

ods rtf close;
[/pre]
Kwok
Calcite | Level 5
Hi Cynthia,

Your example is good but the 2nd table was split between 2 pages. What would your code look like if I want the table not to split ?

Thanks
Cynthia_sas
SAS Super FREQ
Hi:
The NOKEEPN option tells RTF that it's OK for the Word Processor (MS-Word) to split the table between pages. The KEEPN option tells RTF that you want an entire table to stay together, if possible.

So the changed code for the invocation would look like this:
[pre]
ods rtf file='c:\temp\addtext.rtf' keepn startpage=no ;
[/pre]

cynthia
Kwok
Calcite | Level 5
Thanks for your useful code
Andre
Obsidian | Level 7
Cynthia,

ok for this ods rtf text= manner of doing even if my knowledge of english did not permit me
to understand every nuances of a jabberw...!

but why in the three proc print does i have 'subliminal' non printable text before Obs
[pre]
.(. tc "Print" \f \l 1...."Dataset SASHELP CLASS " \f C \1 2)
[/pre]

Andre
Cynthia_sas
SAS Super FREQ
Andre:
ODS RTF inserts RTF control strings into various places in the document in order to build a TABLE OF CONTENTS (IF you turn on the CONTENTS=YES option).

This behavior is described here:
http://support.sas.com/kb/10/379.html

You can disappear the characters with the SHOW/HIDE button inside Word. Or, you can tell ODS RTF not to insert them at all. The ODS option is described in the Tech Support note and to use it, you would have this in your code:
[pre]
ods rtf file='somefile.rtf' notoc_data;
... more code...
ods rtf close;
[/pre]

cynthia
deleted_user
Not applicable
Cynthia,
Thank you so much for the information! As always, you seem to have the answer!! I will test out the different options that you provided, and I will let you know if any of them work for what I need. I have a feeling that the TEXT= method might be sufficient for what I am trying to do.

Thanks again!!

-Phil

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
  • 7 replies
  • 1334 views
  • 0 likes
  • 4 in conversation