The SAS Output Delivery System and reporting techniques

BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

Reply
Respected Advisor
Posts: 3,775

BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

{bygrouplastpage} is not a valid function I am looking for equivalent.

The proc report option BYPAGENO=1 resets the page numbers at the beginning of each by group.  I also want the {lastpage} of the by group as in the RTF {sectionpages} function.

SAS Super FREQ
Posts: 8,721

Re: BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

Hi, I believe this Tech Support note describes what you're seeing and how to get what you want:

39423 - The BYPAGENO= option on the PROC REPORT statement might produce incorrect page numbers

cynthia

Respected Advisor
Posts: 3,775

Re: BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

I've seen that note but I have SAS 9.3 so that is not the issue the numbering is correct.  I want to number "Page n of p" within each by group 1 of 3, 1 of 5 etc.  right now I can only use {lastpage} and I get 1 of 197, 2 of 197, 3 of 197 and for the next group 1 of 197, 2 of 197 etc.  I would like a "{function}" that gives last page of by group.  

Grand Advisor
Posts: 9,596

Re: BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

NULL,

why not make it on your own based on this sample code ? You has so strong data step skill.

options nobyline orientation=landscape;
ods escapechar='^';

proc sort data=sashelp.shoes out=sorted;
   by region;
run;

data _null_;
   set sorted;
   by region;
   if first.region then do;
      count+1;n=0;m=0;
      call symput('region'||trim(left(count)),trim(left(region)));
   end;
   n+1;
   if mod(n,24)=1 then m+1;/*a page has 24 data row -- You need change it according to your SAS system*/
   if last.region then call symput('last'||trim(left(count)),trim(left(m)));
   call symput('count',trim(left(count)));
run;


%put _user_ ;



%macro loopit;
   %do i=1 %to &count;
      options pageno=1;

      proc report data=sashelp.shoes nowd;
         by region;
         where region="&&region&i";
         column subsidiary product stores sales inventory returns;
         define subsidiary/order;
         define product/display;
         define stores/display;
         define sales/display;
         define inventory/display;
         define returns/display;
         title f=Arial h=14pt c=black 'Product Report for the #byval1 Region';
         footnote j=center f=Arial h=8pt c=black "Page ^{thispage} of &&last&i ";
      run;
   %end;
%mend;

ods pdf file='c:\temp\aaa.pdf';
%loopit
ods pdf close;

Xia Keshan

SAS Super FREQ
Posts: 8,721

Re: BYPAGENO=1 with {thispage} of {bygrouplastpage} for PDF destination.

Hi: If you feel it should be available, why not add that as a SAS ballot item? Otherwise, the suggestion in the full code snippet should work for you, too. The first number might be correct, but the solution in the code snippet will fix the last number too, as Ksharp demos -- you can loop through your by groups with a macro program and then the page numbers will do what you want.

cynthia

Ask a Question
Discussion stats
  • 4 replies
  • 463 views
  • 0 likes
  • 3 in conversation