BookmarkSubscribeRSS Feed
Cx
Calcite | Level 5 Cx
Calcite | Level 5
I'm curious to know how to add repeating headers in proc report. I know that the skip option is not honored by the ods printer destination within proc report, and so I have added a compute block with "line ' ';" and "style(lines)={font_size=1pt cellpadding=0 cellheight=10pt}". The resulting report looks too busy with my current template and/or current inline style settings, which contains frame=box and rules=all. I'd like to add a header at the top of each section that is being skipped, but I'm kinda at a loss as to how.

Thanks.
David
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi:
You might try bypassing the use of the LINE ' ' after the group and go with a COMPUTE BEFORE, then. Perhaps something like what you would get if you submitted the code shown below.

cynthia
[pre]
ods pdf file='c:\temp\before_line.pdf' ;
title 'Only Line Before';
proc report data=shoes nowd
style(report)={frame=box rules=all}
style(summary)={font_weight=bold};
where region in ('Asia', 'Canada', 'Pacific');
column region subsidiary sales;
define region /group;
define subsidiary /group;
define sales / sum;
break after region / summarize;
compute before region /
style(lines)=Header{just=l foreground=purple};
line 'Before Region: ' Region $25.;
endcomp;
run;
ods _all_ close;
[/pre]
Cx
Calcite | Level 5 Cx
Calcite | Level 5
Cynthia,

Thanks for your help. The code you provided was useful for a generic header, which seemed to be a component of the table itself. This was close to what I wanted to do, but lacked the detail of the header itself (columns with labels of "Region", "Subsidiary", and "Total Sales") to be repeated for each "table" on the page. So I stumbled (ODS newbie) upon a different approach, in which I employed the "ods layout start rows= 3" prior to my call to proc report, and then using "break after region / page" within proc report to start a new page. I don't know if there happens to be an easier or more correct way to do this, but what results is 3 separate tables on one page, with the header being repeated, which is what I want. It does bring up a different question though. What if I don't know how many tables can be fit onto a single page? How might I be able to only fit complete tables onto a single page?

Here is the code with the layout approach, which on my machine in landscape, puts part of the last table onto a second page:

ods pdf file='c:\temp\before_line.pdf' uniform;
title 'Only Line Before';
ods layout start rows = 3;
proc report data=shoes nowd
style(report)={frame=box rules=all}
style(summary)={font_weight=bold};
where region in ('Asia', 'Canada', 'Pacific');
column region subsidiary sales;
define region /group;
define subsidiary /group;
define sales / sum;

break after region / page ;

compute before region / style(lines)=Header{just=l foreground=purple};
line 'Before Region: ' Region $25.;
endcomp;
run;
ods layout end;
ods _all_ close;

Thanks,
David

Message was edited by: Cx Upon further analysis, I've also discovered that the "ods layout start rows = 3;" statement is no different than "ods layout start columns=1;"

A larger issue that I'm running into with respect to how output is rendered on the page can be seen by looking at all the regions (deleting "where region in ('Asia', 'Canada', 'Pacific');"). This causes the last "table" to be output and mushed up against the second to last table on the page. I don't know why this happens. I'm also using the following options statement, if it helps:

options orientation=landscape center
topmargin=0.25in
bottommargin=0.25in
leftmargin=0.25in
rightmargin=0.25in ;




Message was edited by: Cx
Cynthia_sas
SAS Super FREQ
Hi, David...ODS LAYOUT is still experimental. Because of this, I don't use it very much and don't recommend it for production work except with the warning that it could change between the experimental form and the final production form.

Having said that, I know that a lot of folks are beginning to experiment with ODS LAYOUT and for the quickest, most accurate response, you should contact Tech Support for help with ODS LAYOUT.

cynthia
Cynthia_sas
SAS Super FREQ
David:
Another approach would be to NOT use ODS LAYOUT if this is a production job and to use simple BY GROUP processing and STARTPAGE=NO. BY GROUP processing will give you multiple tables with the column headers where you want them and startpage=no option will put all the by group tables on one page (where possible).

You can then decide whether you need your compute block LINE statement anymore because, by default, you will get a BYLINE. In this case, Region=Asia, etc. You can suppress the BYLINE with the
[pre]
options nobyline; <-- to turn off
or
options byline; <-- to turn on (this is the default)
[/pre]

At any rate, this solution might work for you.
cynthia

[pre]
*** the code;
proc sort data=sashelp.shoes out=shoes;
by region subsidiary;
where region in ('Asia', 'Canada', 'Pacific');
run;

** run once with options nobyline;
** run a second time with options byline;
** to see the difference in how the reports look;
** to uncomment the statement, remove the ** in front of the option statement;

** options nobyline;
ods pdf file='c:\temp\bygrp.pdf' uniform startpage=no;
title 'Use By Group Processing For Separate Tables';
title2 'Use startpage=no to suppress page breaks';

proc report data=shoes nowd
style(report)={frame=box rules=all}
style(summary)={font_weight=bold};
by region;
column region subsidiary sales;
define region /group;
define subsidiary /group;
define sales / sum;

break after region / page ;

/*
compute before region /
style(lines)=Header{just=l foreground=purple};
line 'Before Region: ' Region $25.;
endcomp;
*/

run;

ods _all_ close;
ods listing;
options byline; /* turn on if you have turned off */
[/pre]

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
  • 2817 views
  • 0 likes
  • 2 in conversation