The SAS Output Delivery System and reporting techniques

ODS PDF: split tables across pages

Reply
Regular Contributor
Posts: 171

ODS PDF: split tables across pages

Is there any way to prevent tables from splitting across pages when printing to the ODS PDF destination? I’m looking for something analogous to the KEEPN option that can be used in the RTF destination.

Thanks in advance.
SAS Super FREQ
Posts: 8,743

Re: ODS PDF: split tables across pages

Hi:
PDF does not have the equivalent of the KEEPN option. If your BY groups are small enough to fit on a single page, they you might use BY processing. For most procedures, every BY group starts on a separate page and you can suppress the normal BYLINE behavior with a SAS option (OPTIONS NOBYLINESmiley Wink.

Otherwise, I'm not sure there's a way other than to figure out (for your font size and margin sizes) how many table rows will fit on a page and then to artificially generate each table inside some kind of macro program.

cynthia
Occasional Contributor
Posts: 11

Re: ODS PDF: split tables across pages

You could try adjusting the bottommargin option.
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

The report is over 60 pages with tables of varying length. Unfortunately, no one value for the bottom margin will fix the report in all cases. Thanks nonetheless.
SAS Super FREQ
Posts: 8,743

Re: ODS PDF: split tables across pages

But, how are you creating the tables of varying lengths -- with multiple procedures or with 1 procedure. Are you using BY group processing already?? Are you using the STARTPAGE= option to turn off normal page break behavior??? If you are using STARTPAGE=NO and multiple procedures, then STARTPAGE=NOW will insert a page break between procedures when you determine that you need one. The issue with this is that you may need to do a bit of testing abotu where the page breaks go until you get it right, but without knowing more about how your 60 pages are generated, it's all just a guess.

cynthia
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

The initial ODS PDF statement specifies STARTPAGE=NEVER. The tables are then created with six different proc print steps. The last four print procedures already use by-groups processing. The by-groups are of varying sizes. Generally between one and five by-groups can be printed on a single page. I use STARTPAGE=NOW to insert page breaks between the final four print procedures. The problem occurs when the table corresponding to one by-group is split across two pages. I want to print as many by-groups on a single page as possible without splitting a table across pages. Currently, I’m forced to use the RTF destination with the KEEPN option. I’m then opening the RTF document in Word and printing it to a PDF to get the results I want.

Thanks again.
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

I know my last reply sounds confusing. Here is a silly example that’s analogous to my problem for illustration purposes.

[pre]
data test;
set sashelp.class;
do i=1 to ceil(ranuni(0)*15);
output;
end;
run;

ods listing close;
ods pdf;
ods rtf keepn;
proc print data=test;
by name;
run;
ods _all_ close;
ods listing;
[/pre]

When you run the above code, page breaks will likely occur between names in the PDF document but not in the RTF document. I want to change the PDF document so that as many names are printed on one page as possible without splitting a name across pages.
SAS Super FREQ
Posts: 8,743

Re: ODS PDF: split tables across pages

I understood what you meant. If creating an RTF file with the KEEPN option gives you what you want, then that is probably the best approach. The only other thing you could do to automate the "print to PDF" from inside Word would be to investigate a script or Word macro to do the print to PDF automatically or see if there is an Adobe command language or command line syntax that would allow you to print the RTF directly to PDF, after SAS has made the RTF file.

cynthia
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

Thanks again Cynthia. Has anyone had any luck printing a document to a PDF via the X statement? My knowledge of command line syntax is pretty much nonexistent.
SAS Super FREQ
Posts: 8,743

Re: ODS PDF: split tables across pages

Hi:
While I haven't done printing, I have successfully issued an X command to issue a DOS command (in my case, either MKDIR, CD or COPY or starting a .BAT file). The key is learning what command will work.

My guess is that means either using an Acrobat tool (like Acrobat Distiller) in batch mode or using a VB Script from with Word syntax to 1) open the RTF file into Word, and then 2) print the file to PDF.

I don't do very sophisticated stuff with scripts or bat files or X commands, so I'm not much help.

cynthia
Super User
Posts: 9,681

Re: ODS PDF: split tables across pages

Hi.
I posted the following code I wrote before.
To see whether it is what you want.


[pre]




[/pre]




data base;



 set sashelp.shoes;



 where ranuni(0) ge .5 ;



run;



 



 



ods listing close;



ods pdf file='c:\x.pdf'; * to test the page size of pdf;



proc print data=base;  *column obs is to see how many
lines each page;



run;                   
*34 is the number of lines in one page pdf;



ods pdf close;



ods listing;



 



proc means data=base
nway;



 class region;



 output out=count n=count;



run;



data result;



 merge base count(keep=region count);



 by region;



run;



data result;



 set result;



 mod=mod(count,34);



run;



data result; * To decide Page break
point;



 set result;



 by region;



 retain break 1;



 if last.region then sum_mod+mod;



 if count +sum_mod ge 34 and region ne lag(region) then do;



                                                               
break+
1;



                                                               
sum_mod=
0;



                                                               
end;



run;



options nolabel;



ods listing close;



ods pdf file='c:\report.pdf';



proc report data=result

nowd spanrows;



 column region product subsidiary stores sales inventory returns
break;



  define break /group noprint;



  break after break /page;



run;



ods pdf close;



ods listing;



 






[pre]



Ksharp
[/pre]
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

Cynthia: I appreciate your advice. I’ll research these options for automatic printing to PDF more when I get some free time on my hands.

Ksharp: That’s a pretty clever workaround. I still run into a problem when I use by-groups with the STARTPAGE=NO option. In this case, the PAGE option on the BREAK statement appears to have no affect on the report. I’m sure I could get your code to work for my report if I were to stop using by-groups and use LINE statements to separate the groups instead, although the report would not look exactly the same. I plan to try this method in the near future.

Many thanks to both of you for the help.
SAS Super FREQ
Posts: 8,743

Re: ODS PDF: split tables across pages

You are correct. STARTPAGE=NO ignores the page breaks inserted by the procedures -- hence the need for STARTPAGE=NOW and STARTPAGE=YES.

cynthia
Regular Contributor
Posts: 171

Re: ODS PDF: split tables across pages

Thanks Cynthia. That’s the answer I was afraid of. I was hoping I’d get lucky and stumble across some undocumented or experimental option. Oh well, it was worth a shot :-) I appreciate the advice.
Occasional Contributor
Posts: 7

Re: ODS PDF: split tables across pages

Thank you all for giving solution on preventing PDF splitting. The When I convert Word to PDF, some content was split on two PDF pages, I'm looking for a way for solving it.

And finally I get an idea from upper helps.

Thank you so much.

Best regards.

Ask a Question
Discussion stats
  • 14 replies
  • 1815 views
  • 0 likes
  • 5 in conversation