BookmarkSubscribeRSS Feed
Olivier
Pyrite | Level 9
Hi all.

When I submit [pre]
ODS RTF FILE = "c:\temp\good.doc" CONTENTS ;
PROC PRINT DATA = sashelp.class ;
RUN ;
ODS RTF CLOSE ;
[/pre]
I get a page break after the content table. That's fine with me.
Unfortunately, when I add a BODYTITLE option to my ODS RTF statement, the page break disappears (shazam !). Adding an extra ODS RTF STARTPAGE=NOW ; before the Print Procedure doesn't bring the page break back.
[pre]
ODS RTF FILE = "c:\temp\good.doc" CONTENTS BODYTITLE ;
ODS RTF STARTPAGE = NOW ;
PROC PRINT DATA = sashelp.class ;
RUN ;
ODS RTF CLOSE ;
[/pre]
Is there any circumvention (maybe inline formatting to insert page break ?) ?
Is it something that was intended to behave that way ? (If I can't avoid the problem, at least I want to put an explanation on it, if possible...)

Thanks in advance.
Olivier

PS : This time, Cynthia, I don't think that Proc Report, how wonderful it may be, will solve my problem.
4 REPLIES 4
wayne_sas
SAS Employee
Yes. You found a problem. It stems froma request in BODYTITLE functionality to not force page breaks on the section data. It places a \sbknone on the section and, when needed, uses the rtf spec "\page" for the page break. It interacts very poorly with the request for the table of contents page at the top.

It was fixed in the NEXT RELEASE, which does you no good at all.

You can get part way there with raw rtf.

ods escapechar="*";
ODS RTF FILE = "good.rtf" BODYTITLE toc_data ;
ods rtf prepage="*R'{Table of Contents} \line \pard\plain{\field\fldedit{\*\fldinst {\fs24 TOC \tcf67 \\h }}} \page' ";
PROC PRINT DATA = sashelp.class ;RUN ;

But since the titles are in the body, you lose them over the Proc Print. You'll constantly be trying to compensate for the first problem.

SAS Tech Support may be able to offer a macro that will post process the rtf and remove the offending \sbknone.
Cynthia_sas
SAS Super FREQ
Olivier:
Here's a program that works for me, It takes out the \sbknone and so I still get the contents AND bodytitle for the PROC PRINT works as expected..
[pre]
ods rtf file='c:\temp\toc_bt.rtf' contents bodytitle;

proc print data=sashelp.class;
title 'Proc print';
run;
ods rtf close;


filename old_in "c:\temp\toc_bt.rtf";
filename toc_out "c:\temp\newout.rtf";

data _null_;
infile old_in lrecl=4096 recfm=v length=ln;
file toc_out lrecl=4096 recfm=v;
input;
where_sbk = index(_infile_,'\sbknone');
/* this is the line we want to change */
/* \sect\sectd\linex0\endnhere\sbknone */
/* if where_sbk gt 0 AND you are on a \sect line this */
/* will ensure that you delete the RIGHT \sbknone */
if where_sbk gt 0 and index(_infile_,'\sect') gt 0 then do;
_infile_=substr(_infile_,1,where_sbk-1)||substr(_infile_,where_sbk+8);
** have changed the length of the _infile_ line by taking out \sbknone string;
** so reset the length variable for _INFILE_;
ln = length(_infile_);
end;

put _infile_;
run;

** Now, check the log and assuming no errors;
** open the NEW "processed" RTF file with Word -- you will NOT ;
** see the file in the SAS Results Window because it was created;
** with a DATA step program.;

[/pre]

Happy Holidays! (I don't do EVERYTHING in PROC REPORT....)
cynthia
wayne_sas
SAS Employee
An alternate is a macro you could store off for re-use, unitl 9.2.

%macro top_page(source=xxx);
data temp ;
length line $400;
infile &source length=lg lrecl=1000 end=eof;
input @1 line $varying400. lg;

data _null_;
set temp ; retain flag 1 ;
file &source;
if ( flag ) then do;
if (index(line,"\sbknone") > 0) then do ;
line = tranwrd(line,"\sbknone","");
flag = 0 ;
end ;
end;
put line;
%mend;

filename rtf "good.rtf" ;

ODS RTF FILE = "good.rtf" CONTENTS BODYTITLE toc_data ;
PROC PRINT DATA = sashelp.class ;RUN ;
ODS RTF CLOSE ;

%top_page(source=rtf) ;
Olivier
Pyrite | Level 9
Thank you both Wayne & Cynthia for explanations and solutions to solve my problem.
Wayne, I've tested something with raw RTF, and this short version of your code seems to be enough (it allows me to leave the CONTENTS options and prevents from generating the content tables by myself) : [pre]
ODS RTF FILE = "c:\temp\good.doc" CONTENTS BODYTITLE ;
ODS ESCAPECHAR = "^" ;
TITLE1 "^R'{\page}'" ;
PROC PRINT DATA = sashelp.class ;
RUN ;
TITLE ;
ODS RTF CLOSE ;
[/pre]
And as usual, I'll wait for 9.2 impatiently.
Regards,
Olivier

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