Hi:
Using a BY statement will automatically cause PROC REPORT to start every BY group at the beginning of a new page. So if your BY group will all fit on one page, then if you have 3 by groups, you would have a 3 page report. BY group processing does not work any differently when you use #BYVAL/#BYVAR or not. You can see from the #1 report and #2 report below that each report contains 3 pages -- because of the BY statement.
The difference is that if you compare report #3, without a BY statement, to the other 2 reports, this report has only 1 page (as compared to 3 pages). The BREAK statement still does a summary for each region, but since there is no BY statement, each region is on the same page. The empty line between regions comes from the LINE statement in the COMPUTE block for REGION.
The side effect of a BY statement is that you get every BY group on a separate page -- that's why the use of #BYVAL works in a TITLE -- because the BY information is available to be used.
If you further look at the #4 report -- you will see how a COMPUTE BEFORE can be used to put a header above every REGION value.
cynthia
[pre]
options nodate pageno=1;
proc sort data=sashelp.shoes out=shoes;
by region product;
run;
ods listing;
ods pdf file='useby1.pdf';
ods rtf file='useby1.rtf';
ods html file='useby1.html' style=sasweb;
proc report data=shoes nowd;
by region;
title '1) use by statement';
where region in ('Asia', 'Pacific', 'Canada');
column product sales inventory returns;
define product / group;
define sales / sum;
define inventory / sum;
define returns/ sum;
rbreak after / summarize;
run;
ods _all_ close;
options nodate pageno=1 nobyline;
ods listing;
ods pdf file='useby2.pdf';
ods rtf file='useby2.rtf';
ods html file='useby2.html' style=sasweb;
proc report data=shoes nowd;
by region;
title '2) use BYVAL statement for #byval1';
where region in ('Asia', 'Pacific', 'Canada');
column product sales inventory returns;
define product / group;
define sales / sum;
define inventory / sum;
define returns/ sum;
rbreak after / summarize;
run;
ods _all_ close;
options byline;
options nodate pageno=1;
ods listing;
ods pdf file='noby3.pdf';
ods rtf file='noby3.rtf';
ods html file='noby3.html' style=sasweb;
proc report data=shoes nowd;
title '3) No BY statement in this proc report';
where region in ('Asia', 'Pacific', 'Canada');
column region product sales inventory returns;
define region / group;
define product / group;
define sales / sum;
define inventory / sum;
define returns/ sum;
break after region / summarize;
compute after region ;
line ' ';
endcomp;
run;
ods _all_ close;
options nodate pageno=1;
ods listing;
ods pdf file='noby4.pdf';
ods rtf file='noby4.rtf';
ods html file='noby4.html' style=sasweb;
proc report data=shoes nowd;
title '4) No BY statement -- use COMPUTE BEFORE';
where region in ('Asia', 'Pacific', 'Canada');
column region product sales inventory returns;
define region / group noprint;
define product / group;
define sales / sum;
define inventory / sum;
define returns/ sum;
break after region / summarize;
compute after region ;
line ' ';
endcomp;
compute before region /
style=Header{just=l font_weight=bold};
before_line = catx(' ','Region:',trim(region));
line before_line $100.;
endcomp;
run;
ods _all_ close;
[/pre]