BookmarkSubscribeRSS Feed
Not applicable
Is there a way to include page numbers on graphs created by proc gchart and ouput to the PDF destination? I'm using SAS 9.2.


Rhodochrosite | Level 12
How automatic do the page numbers need to be? Do they need to be on the graph it self or just on the page that contains the graph (will the graph be imbedded in a report or table or on its own)?

SAS/GRAPH is not going to 'know' the page when the graph is rendered. So to place the number on the graph you will have to know and then pass the number into the graph. It might be easier to insert the graph into a table, even a layout page, which will receive its number automatically.
Not applicable
I should have been more specific. The program creates a series of graphs with BY group processing. I thought I remembered reading somewhere that with SAS/Graph 9.2 it was possible to use the {thispage} function. I was hoping there was an easy way to do it that I was just missing. I seems like a pretty common thing to want to do.

I'm going to try to create a macro variable that contains the page number for each BY value and output that in a footnote.


I believe that in-line formatting (such as {thispage}) works for RTF in SAS 9.2, but not for PDF (yet). The reason that using in-line formatting works at all in titles for RTF is that there is a NOGTITLE and NOGFOOTNOTE option for RTF destination, that tells SAS/GRAPH to let ODS control the title and footnote. PDF does not currently have those options (although it is planned for SAS 9.3). You can find the description of the GTITLE option for RTF here:

(Of course, there are no page numbers in HTML output, so {thispage} would not ever work in ODS HTML for that reason. But other in-line formatting will work in HTML and NOGTITLE will work for HTML, as well.)

So, you can't use {thispage} with ODS PDF in SAS 9.2 -- however a simple NUMBER system option will work with SAS/GRAPH in SAS 9.2 for ODS PDF, as shown in the program below. When I run the code, I get 3 pages of output, one for each BY group from the GCHART and the page number is in the upper right hand corner of each page.

ods listing close;
options nodate number pageno=1;

proc sort out=shoes;
where region in ('Asia', 'Pacific', 'Canada');
by region product;

ods pdf file='c:\temp\sasgraf_page_option.pdf';

proc gchart data=shoes;
by region;
title 'Use NUMBER System Option';
vbar product / sumvar=sales;
ods pdf close;
title; footnote;

** Compare RTF output;
ods listing close;
options nodate nonumber;

ods rtf file='c:\temp\sasgraf_nogtitle_option.rtf' nogtitle;

ods escapechar='^';
proc gchart data=shoes;
by region;
title j=c 'RTF with NOGTITLE' j=r 'Page ^{thispage}';
vbar product / sumvar=sales;
ods rtf close;



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3 in conversation