BookmarkSubscribeRSS Feed
craig159753
Quartz | Level 8

Hi,

 

I have a trivial question, considering the following dataset (MY_DATASET):

 

 

/*
Variable1 | Variable2 | Variable3 | Variable4 | Variable5 | Page | PageNumbering |

----------------------------------------------------------------------------------

xxxx1     | AAAAA     | YY        | LLL       | W         | 1    | Page 1 of 8   |
xxxx2     | AA        | YYY       | LLLLLL    | WWWWWWWW  | 1    | Page 1 of 8   |
xxxx3     | AAA       |           | L         | WWW       | 1    | Page 1 of 8   |
xxxx4     | AAAAA     | YY        | LLL       | W         | 2    | Page 2 of 8   |
xxxx5     | AA        | YYY       | LLLLLL    | WWWWWWWW  | 2    | Page 2 of 8   |
xxxx6     | AAA       |           | L         | WWW       | 2    | Page 2 of 8   |
... */

 

 

Consider the following PROC REPORT code:

 

proc report data=my_dataset headline nowd split="@" missing spacing=1;
  column variable1 variable2 variable3 variable4 variable5;
  by page;

  %* ID Variable(s);
  define variable1 / order order=internal id;
  %* Page 1;
  define variable2 / display;
  define variable3 / display;
  %* Page 2;
  define variable4 / display;
  define variable5 / display;

  compute before _page_;
    line @1 pagenumbering $200.;
  encomp;
run;

Note: the code will produce an ODS RTF output. I have left this code off for simplicity.

 

 

As you can see, the code above will produce a "wide" PROC REPORT. What I mean by this, the output will produce two pages for every value of the PAGE variable:

 

Page 1 of x

Page=1

PageNumbering=Page 1 of 8

Variable1 Variable2 Variable3

 

Page 2 of x

Page=1

PageNumbering=Page 1 of 8

Variable1 Variable4 Variable5

 

  • Variable1 being the ID variable appearing on all pages.
  • Variable2 and Variable3 appearing on the first page.
  • Variable4 and Variable5 appearing on the second page.

 

The Issue:

The current code will print a line of text above the table on each page via the COMPUTE block. However, as the output is wide the page numbering is repeating, and I know why, but I was curious is there a nice solution, that I do not know about, which will give me the correct page numbering per page.

 

Page 1 of 16

Variable1 Variable2 Variable3

 

Page 2 of 16

Variable1 Variable4 Variable5

 

Notice the Pagenumbering variable has changed 8 to 16 (due to there are technically 2 pages per page as the output is wide) and that the page number is counting correctly. Note, I have created two new PageNumbering variables, so I have these at my disposal too:

 

/*
Variable1 | Variable2 | Variable3 | Variable4 | Variable5 | Page | PageNumbering | PageNumbering1 | PageNumbering2 |
-------------------------------------------------------------------------------------------------------------------------
xxxx1     | AAAAA     | YY        | LLL       | W         | 1    | Page 1 of 8   | Page 1 of 16   | Page 2 of 16   |
xxxx2     | AA        | YYY       | LLLLLL    | WWWWWWWW  | 1    | Page 1 of 8   | Page 1 of 16   | Page 2 of 16   |
xxxx3     | AAA       |           | L         | WWW       | 1    | Page 1 of 8   | Page 1 of 16   | Page 2 of 16   |
xxxx4     | AAAAA     | YY        | LLL       | W         | 2    | Page 2 of 8   | Page 3 of 16   | Page 4 of 16   |
xxxx5     | AA        | YYY       | LLLLLL    | WWWWWWWW  | 2    | Page 2 of 8   | Page 3 of 16   | Page 4 of 16   |
xxxx6     | AAA       |           | L         | WWW       | 2    | Page 2 of 8   | Page 3 of 16   | Page 4 of 16   |
... */

So Variable2 and Variable3 would use PageNumbering1 and Variable4 and Variable5 would use PageNumbering2.

 

Things I have already tried (some work):

  • Looping the PROC REPORT per page (works but very slow on large datasets)
  • Using the ODS RTF ^{this page} stuff (works but when I combine outputs the page numbering is linked to the entire document and not the output itself).

Any thoughts welcome.

 

1 REPLY 1
Norman21
Lapis Lazuli | Level 10

Have you had a look at this post?

 

https://communities.sas.com/t5/ODS-and-Base-Reporting/Page-number-at-top-and-page-break-after-each-p...

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1061 views
  • 0 likes
  • 2 in conversation