Help using Base SAS procedures

Page counter

Occasional Contributor
Posts: 5

Page counter

I need to count how many observations fit on page in proc report. How to compute variable pagenum (e.g.) which consists page number?

Logic of this procedure (in pseudocode) is following:

L - number of rows per page

pagenum = 1

counter = 0

for observation in dataset:              #go through all observations in dataset

     counter += HowManyRows(observation)     #HowManyRows function returns number of rows which observation deposite on page

     if counter <= L*pagenum then:

          pagenum                              #write value pagenum into pagenum variable in datastep


          pagenum = pagenum + 1     #write value pagenum into pagenum variable in datastep

How to write similar logic in SAS?

At the end I'll obtain datastep with pagenum variable and I can write line statments before every page. Last question: does this line shift page content by 1 row and the last page row transfers to the next page?

Super User
Super User
Posts: 9,599

Re: Page counter

Posted in reply to S_Proskurnin

You question is a very complex one, and there are several papers out there.  You have to take into consideration font size, page orientation, width/height, style, line wrapping etc. And then it might not work.  If you just want page numbers then for RTF/PDF you can use:

ods escapechar= "^";

footnote j=r "Page ^{thispage} of ^{lastpage}";

That way pages are automatically generated for you.

Or the way I tend to do things, generate the output once, look at it and decide that maybe I want ten observations per page:

data want;

     set have;



And use pgno as my break on / page in the proc report.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation