%macro pagenum;
   %global lastpage;
   filename temp 'temporary_file';

   proc printto print=temp new;

   data test;
      x=1;

   options number;
   proc print;

   proc printto;

   data _null_;
   infile temp truncover;
   input record $ 1-200;
   call symput('lastpage',trim(left(put(input(reverse(
        scan(
      reverse(record),1)),6.)-1,6.))));
   stop;
 run;

 options pageno=&lastpage;
%mend pagenum;

/* Place code that generates your report here  */

%pagenum
%put *The last page number generated is &lastpage;