The SAS Output Delivery System and reporting techniques

Page X of Y not work in WORD 2007

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Page X of Y not work in WORD 2007

In SAS 9.3  I run the sample code in  http://support.sas.com/kb/24/602.html

Table of content worked. But footnote  Page X of Y not resolved in WORD 2007. Still as following:

{Page}  {field{*fldinst { PAGE }}}~of~{field {*fldinst{ NUMPAGES }}}

 

Anyone can help?

Randy


Accepted Solutions
Solution
‎11-24-2011 10:51 AM
SAS Super FREQ
Posts: 8,743

Re: Page X of Y not work in WORD 2007

Hi:

  That code uses DATA _NULL_ techniques and there are no FOOTNOTE statements in the code. Did you add a FOOTNOTE statement to the code AND, you also have to add an ODS ESCAPECHAR statement to the code??? And, what do you mean when you say that the TOC did not work? Did you see a (mostly) empty page that had a title of TABLE OF CONTENTS at the top of the empty page? And if you saw the empty page, did you right click and tell Word to update the fields??? With the CONTENTS= option, RTF sends the RTF control codes for creating the TOC, but you must manually go to the first page and tell Word to update the fields to create the TABLE of CONTENTS.

cynthia

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,743

Re: Page X of Y not work in WORD 2007

Hi:

  I no longer have Office 2007 to work with, but I have used and tested the ODS ESCAPECHAR method of generating Page X of Y in Word 2003, 2007, and 2010. ODS ESCAPECHAR methods DO work in all these versions of Word, whether I use {THISPAGE} and {LASTPAGE} or {PAGEOF} (RTF only). In some instances, Word had to be forced to repaginate in order to see the results; in other instances, I had to switch into Page Preview or Print Preview mode. The only instance where Page X of Y does not work with ODS RTF is when you try to use the BODYTITLE option with the ODS ESCAPECHAR method of generating Page X of Y page numbers.

  Since you did not provide code, I'm not sure what's happened. I would recommend a simple test:

options nodate nonumber;

 

ods listing close;

ods rtf file='testpgno.rtf';

ods escapechar='^';

title j=r 'Title: This is Page ^{pageof}';

footnote j=r 'Footnote: This is Page ^{thispage} of ^{lastpage}';

footnote2 j=r 'Footnote2: -- ^{thispage} --';

  

proc print data=sashelp.shoes noobs;

run;

  

ods rtf close;

If the above test does NOT work for you to get page X of Y page numbering, then I would recommend that you open a track with Tech Support. If the above test DOES work for you, then I would recommend that you compare the above code to your code and adjust your code accordingly.

cynthia

Contributor
Posts: 35

Page X of Y not work in WORD 2007

Probably a silly suggestion, but does hitting Alt-F9 in the Word document help?

Occasional Contributor
Posts: 16

Page X of Y not work in WORD 2007

Dear Cyntia,

Your code worked.  But after I rerun the code in  http://support.sas.com/kb/24/602.html

what strange  are:

1)  There is no Footnote in rtf

2) TOC not worked.

I follow the following instruction:

/* In SAS 9.2 use: ods rtf file='c:\temp\contents.rtf' contents toc_data; */

Randy

Solution
‎11-24-2011 10:51 AM
SAS Super FREQ
Posts: 8,743

Re: Page X of Y not work in WORD 2007

Hi:

  That code uses DATA _NULL_ techniques and there are no FOOTNOTE statements in the code. Did you add a FOOTNOTE statement to the code AND, you also have to add an ODS ESCAPECHAR statement to the code??? And, what do you mean when you say that the TOC did not work? Did you see a (mostly) empty page that had a title of TABLE OF CONTENTS at the top of the empty page? And if you saw the empty page, did you right click and tell Word to update the fields??? With the CONTENTS= option, RTF sends the RTF control codes for creating the TOC, but you must manually go to the first page and tell Word to update the fields to create the TABLE of CONTENTS.

cynthia

Occasional Contributor
Posts: 16

Re: Page X of Y not work in WORD 2007

Dear Cynthia,

Right click do the trick for TOC.

I guess the footnote problem is because template overwrite by other program when I run the sample code.

Thanks!

SAS Super FREQ
Posts: 8,743

Re: Page X of Y not work in WORD 2007

Hmmm...well, I ran the sample program, with a footnote statement and an ODS ESCAPECHAR statement and using Page X of Y functions in the footnote and in Office 2010, I got the right page numbers when I ran the code. As I said, I have used Page X of Y in my code with Office 2003, Office 2007 and Office 2010. I'd recommend that you work with Tech Support -- there's nothing I can think of in the template that would interfere with the page numbers. Tech Support can look at all your code and test opening the output in the version of Word that is the same as yours.

cynthia

** here is the code I used to create the screenshot taken in Word 2010;

** the attached screenshot shows the bottom of page 2 and the top of page 3;

options nodate nonumber;

ods escapechar='^';

ods listing close;

          

ods rtf file='c:\temp\data_step_contents.rtf'

    contents toc_data;

        

footnote j=r 'Footnote: This is Page ^{thispage} of ^{lastpage}';

footnote2 j=r 'Footnote2: -- ^{thispage} --';

                 

ods proclabel "Ms. Crabapple's Class";

          

title 'Class Health Information';

data _null_;

  file print ods; /* Use default table template */

  set sashelp.class;

  put _ods_;

run;

          

ods proclabel "Teacher - Crabapple";

       

title 'Class Roster - Girls';

data _null_;

  file print ods=(variable=(name age));

  set sashelp.class (keep=name sex age);

  where sex='F';

  put _ods_;

run;

          

ods proclabel "Teacher - Crabapple";

title 'Class Roster - Boys';

data _null_;

  file print ods=(variable=(name age));

  set sashelp.class (keep=name sex age);

  where sex='M';

  put _ods_;

run;

             

ods _all_ close;

ods listing; /* Reopen listing */


data_step_contents_rtf.jpg
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 319 views
  • 0 likes
  • 3 in conversation