BookmarkSubscribeRSS Feed
data_null__
Jade | Level 19

{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.

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

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

data_null__
Jade | Level 19

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.  

Ksharp
Super User

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

Cynthia_sas
SAS Super FREQ

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3392 views
  • 0 likes
  • 3 in conversation