BookmarkSubscribeRSS Feed
derekmor54
Obsidian | Level 7

A quick question: is there a way to force a page break in the middle of a table when using RWI? Sample code:

 

ods _all_ close;
ods pdf file="&outpath/rwitest.pdf";
options nodate nonumber;

title;
footnote;

proc sort data=sashelp.baseball out=baseball;
by team name;
run;

data _null_;
length dataval $ 200;
set baseball end=last;
by team;
if _n_ eq 1 then do;
   declare odsout o();
   o.table_start();
   o.body_start();
end;

if first.team and _n_ ne 1 then
   o.page();
 
dataval = catx(' - ',team,name);
o.row_start();
o.format_cell(data: dataval);
o.row_end();

if last then do;
   o.body_end();
   o.table_end();
   o.delete();
end;
run;

ods pdf close;

This has to run inside SAS Studio.

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:
My understanding is that you may not be able to force a page break with RWI under some conditions such as with ODS LAYOUT. However, unless your desired output is more complex, you could use PROC REPORT or a SAS Macro program to handle the page breaking, as an alternative.

But it looks like you want to end the table for each BY group, so I think you need to use your o.page() on the FIRST.TEAM and LAST.TEAM conditions. Here's what I was able to produce with this approach (using only 2 teams):

Cynthia_sas_0-1650462328055.png

Although I think for a simple report such as you show, my tendency would be to use PROC REPORT. But I suspect your real report must be more complex.

Cynthia

derekmor54
Obsidian | Level 7

Yes, my situation is more complicated; it's more akin to:

data _null_;
length dataval $ 200;
set baseball end=last;
by team position;
retain page 1;
if _n_ eq 1 then
   declare odsout o();

if first.team then
   o.table_start();

dataval = catx(' - ',position,team,name);
o.row_start();
o.format_cell(data: dataval);
o.row_end();

if last.position then do;
   o.row_start();
   o.format_cell(data:page,overrides:'just=r');
   o.row_end();
   o.page();
   page + 1;
end;
   
if last.team then 
   o.table_end();
   
if last then 
   o.delete();
run;

ods pdf close;

Suppressing the PDF bookmark that gets generated at the table_start() method is the issue. Fortunately, a PROC REPORT soluition already exists, but this was for an independent validation that explicitly did not use PROC REPORT. However, from a little further testing and your code, it looks like the PAGE() method doesn't work without closing the table.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 349 views
  • 1 like
  • 2 in conversation