The SAS Output Delivery System and reporting techniques

ODS PDF - last page number by group variable

Reply
Occasional Contributor
Posts: 5

ODS PDF - last page number by group variable


Hi ,

I have been trying to output a data with several groups into a single PDF which has several group IDs. I need to print the data by group ID and also everytime group ID changes , page should start at page 1.  I need a foot note as page 1 of 10 where 10 is the last page of that group in group ID and not the total number of pages in PDF.  I used page ~{startpage} of ~{lastpage} in the footnte where ~ is escapechar and options pageno=1 before proc report. this gives me page numebr 1 at the start of each group but last page gives me the total number of pages in PDF instead of last page of that particular group.

for example: group1 - I need footnote page 1 of 10, 2 of 10 etc.. if there are 10 pages in that group.

                    group2 - foot note must be 1 of 5, 2of 5 etc.. if there are 5 pages in group2.

But what I am getting right now is page 1 of 15, 2of 15 etc.. for group1 and when group2 starts it is page 1 of 15, 2of 15 etc...

I have attached my sample output in PDF and sas code in txt file. Appreciate your inputs.

Attachment
Super Contributor
Posts: 307

Re: ODS PDF - last page number by group variable

Chang C. Chung has published a paper called "Page X of Y with Proc Report" (http://changchung.com/download/pageXofY_draft.pdf) that details a macro method of doing this. You should be ablet to adapt the macro (starts on page 3) to work with your by groups.

Another option would be to figure out the number of rows that will fit on one page, and then create a separate "numpages" var for each by group (increment by one whenever the count of obs for a bygroup exceeds the number of rows that will fit on a page). The obvious disadvantage of this approach is that it is dependent on set font sizes, spacing, page sizes, etc.

Yet another option would be to output a separate PDF file for each by group, which would require moving your ods pdf file statement inside the do block. Example (fictional variable called dummy used for illustration):


%macro pdfrep;
%do i=1 %to &tot.;
  options pageno=1;
  ods pdf file="sample&&grpid&i. .pdf" notoc ;
  proc report data=group_prov1 nowd style={rules=none frame=void};
     *by group_id;
     where group_id=&&grpid&i.;
     column   group_id dummy;
     define group_id / group "group" ;
  define dummy / order ;
     title j=c "sample" ;
     footnote j=r "Page ~{thispage} of ~{lastpage}";
  run;
  title;
  footnote;
%end;
ods pdf close;
%mend;
%pdfrep;

SAS Super FREQ
Posts: 8,814

Re: ODS PDF - last page number by group variable

There are many pagexofy macros floating around since before ODS. But you might want to open a track with Tech Support. The cleanest option is to make a separate PDF for every BY group and use the SAS system option to start at 1 with the page numbers. Then use some PDF "combiner" software to manually combine the separate group files into 1 big file or multiple files. The dummy page break variable is also a tried and true method, but you may not be able to make the page numbering cooperate the way you want with that approach.

cynthia

Occasional Contributor
Posts: 5

Re: ODS PDF - last page number by group variable

Hi Fugue and Cynthia.

Thanks for the reply. I also tried Chang C. Chung's paper on page X of Y, but it doesn't work properly in this case. I have actually tried all the possible macros and all of them do work fine when there is a single PDF for each by group, but not with the multiple groups into single PDF. However, I right now am creating separate PDF file for each group.

Thanks again for the response.

Dharmendra

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