The SAS Output Delivery System and reporting techniques

RTF Table of contents

Reply
N/A
Posts: 0

RTF Table of contents

I would like to generate an automatic table of contents in Word using the wordstyle and prepage statements. When I try to do this, the table of contents looks fine, but the text specified in the prepage statement is within a little one-celled table. Is there a way to change this and make the text of the prepage statement look more like a title? I would also like to change the font.

Thanks!

Below is my code:

options nodate nonumber;
ods noptitle;
ods rtf file='F:\newdoc.rtf' bodytitle wordstyle="{\s1 Heading 1;}" contents notoc_data;
ods escapechar='\';

ods rtf prepage='\R/RTF"\s1 " Names; run;

proc freq data=sashelp.class;
tables name;
run;

ods rtf close;
Frequent Contributor
Posts: 91

Re: RTF Table of contents

Posted in reply to deleted_user
ods rtf prepage='\R/RTF"\s1 " Names; run;


You're missing a single quote somewhere on the line above, but I doubt that will "fix" your problem.
SAS Employee
Posts: 20

Re: RTF Table of contents

Posted in reply to deleted_user
I believe the box you see is from a gridline around the text. One the "table" pull down in Word, you can cut the grid lines off.

Also, the prepage line should look more like :
ods rtf prepage='\R/RTF"\s1 Names"'; run;

I don't beleive there is a prepage style in 9.1. There is in 9.2. To get the text to appear like a title, you can use :
ods rtf prepage='\R/RTF"\s1\b\i Names"'; run;

to get it bold and italic.
N/A
Posts: 0

Re: RTF Table of contents

Posted in reply to wayne_sas
Even if I make the gridlines around the prepage text invisible, the text is still part of the table, and I want the actual text to not be part of the table, but separate like a title. Is this possible?

In SAS 8, you could just use a title statement to make a table of contents, but this seems not to work in SAS 9, so I wanted to try it with the prepage statement. I am not getting the results I want.

Thanks.
SAS Super FREQ
Posts: 8,866

Re: RTF Table of contents

Posted in reply to deleted_user
Hi:
I guess that as powerful as prepage and wordstyle are, I find that I can do a lot with simpler techniques.

Ever since ODS PROCLABEL and CONTENTS=YES work together, I find that many of the kinds of thing I was tempted to do with WORDSTYLE, I can do with ODS PROCLABEL and the string I specify there shows up automatically in the Table of Contents created with CONTENTS=YES. (see code sample below)

This paper is a presentation that covers 3 different RTF Table of Contents methods. Perhaps it will be useful to you:
http://www2.sas.com/proceedings/forum2007/097-2007.pdf

cynthia
[pre]
ods rtf file='somefile.rtf' bodytitle contents=yes;

ods proclabel 'First Procedure';
proc freq data=sashelp.shoes;
table product;
run;

ods proclabel 'Second Procedure';
proc print data=sashelp.shoes(obs=5) contents='Proc Print';
run;

ods proclabel 'Third Procedure';
proc means data=sashelp.shoes min mean max std;
class product;
var returns;
run;

ods rtf close;
[/pre]
N/A
Posts: 0

Re: RTF Table of contents

Posted in reply to Cynthia_sas
Hi,

I have already tried using the ods proclabel and contents=yes, but these provide a way more detailed TOC than I need. All I want is to have the variable name in the TOC, I don't need the detailed list (sometimes there are three entries for just one table!)

I have thoroughly read through the paper that you reference already and found the second method (with the wordstyle option) to be the most convenient. However, I was just frustrated that I could not change the prepage text from not being part of the table.

However, if I do decide to live with the fact that the text is in a table, how can I change the font? One poster above mentioned being able to change it to bold and italic, but how can I change the font face? I have created my own style with proc template, but can't figure out which style I would have to change in the template to change the prepage text. If I can also do it in the ods prepage statement, then that would be okay as well.

Thanks!
SAS Super FREQ
Posts: 8,866

Re: RTF Table of contents

Posted in reply to deleted_user
Hi:
I believe that to change the font face, you'd have to define a Word Style or change a Word Style (in normal.dot) so that Heading1 was a particular font face. This is a good question for Tech Support.

I'd probably take a different approach instead of prepage. It sounds to me like you want to change the hierarchy in the table of contents -- to flatten the levels that you see. So this might be a good job for ODS DOCUMENT.

ODS DOCUMENT allows you to create a DOCUMENT from your procedure's output objects -- it's like a "frozen" image of your output objects after the procedure is finished, but before the output objects get sent to the final ODS destination.

That means you can rearrange the output objects or make new folders or flatten the hierarchy of the folder structure. I generally do this by creating one copy of the "original" structured document and then making a new document store with the structure I want. That way, I have a backup of the original output objects and I can always prove that I did nothing to change the output from the procedure, I just rearranged it.

Then, once I've done the rearranging and/or relabeling I want, I can REPLAY the new ODS DOCUMENT to whatever destination I want. There is a point and click window that lets you do the rearranging and renaming very easily. Since it's a LOT of steps, I took the easy way out and built a program using the batch syntax of PROC DOCUMENT to do the same thing as I would do in the point and click window, but it has the added advantage of being something that I can post and you can run (in SAS 9.1.3).

ODS DOCUMENT/PROC DOCUMENT has some limitations in SAS 9.1.3 and you can read about them in the Compatibility section here:
http://support.sas.com/rnd/base/ods/odsdocument/ref.html
For what's new with ODS DOCUMENT in SAS 9.2, there's information here:
http://support.sas.com/rnd/base/new92/92document.html

Note that if you use my code, then the document store goes away when the SAS session is over because I have written everything to the WORK library.

cynthia

The ODS DOCUMENT way to "flatten" the table of contents:
[pre]
title;
footnote;
options nodate nonumber center orientation=portrait;
ods noptitle;
ods listing;

** make a subset of data;
proc sort data=sashelp.shoes out=shoes;
by region;
where region in ('Asia', 'Pacific');
run;

** make a new document store;
** and show the "original" RTF contents;
ods document name=work.shoedoc(write);
ods rtf file='c:\temp\origrtf_file.rtf' contents=yes;
proc means data=shoes min mean max;
by region;
var Sales;
class product;
run;

proc freq data=shoes;
by region;
table product;
run;
ods rtf close;
ods document close;

** Get information on the new ODS DOCUMENT;
** specifically, the names of the output objects for later copying;
proc document name=work.shoedoc;
list;
run;
list / levels=all;
run;
quit;

** now build a new document store with the folder structure;
** and object names and labels we want;
** but I had to know the "official" object names which I cut and pasted from;
** the LISTING in the step above;
** And, there is a stray page break that I want to take out before the PROC MEANS;
** Summary object for Asia;
** I could also insert page breaks, but that is a different example;
** I also want to add some titles and some "before" notes that will;
** be different for Asia and Pacific.;
proc document name=work.newshoedoc2(write);
make ASIA, PACIFIC;
run;
dir;
run;
dir ASIA;
dir;
run;
copy \work.shoedoc\Freq#1\ByGroup1#1\Table1#1\OneWayFreqs#1 to ^;
copy \work.shoedoc\Means#1\ByGroup1#1\Summary#1 to ^;
run;
dir \PACIFIC;
copy \work.shoedoc\Freq#1\ByGroup2#1\Table1#1\OneWayFreqs#1 to ^;
copy \work.shoedoc\Means#1\ByGroup2#1\Summary#1 to ^;

obpage \ASIA#1\Summary#1 / delete;
setlabel \ASIA 'Region=Asia';
setlabel \ASIA#1\OneWayFreqs#1 'Product';
setlabel \ASIA#1\Summary#1 'Sales';
setlabel \PACIFIC 'Region=Pacific';
setlabel \PACIFIC#1\OneWayFreqs#1 'Product';
setlabel \PACIFIC#1\Summary#1 'Sales';

obtitle1 \ASIA#1\OneWayFreqs#1 'New Title for Asia';
obbnote1 \ASIA#1\OneWayFreqs#1 'Not many Boots sold here.';

obtitle1 \PACIFIC#1\OneWayFreqs#1 'New Title for Pacific';
obbnote1 \PACIFIC#1\OneWayFreqs#1 'More Boots sold here.';

run;
quit;

ods listing close;

options nodate nonumber orientation=portrait center;
** now replay the new document store with the contents= option;
ods rtf file='c:\temp\newtoc.rtf' contents=yes;
proc document name=work.newshoedoc2;
replay;
run;
quit;
ods _all_ close;

ods listing;

[/pre]
Contributor
Posts: 35

Re: RTF Table of contents

Posted in reply to Cynthia_sas
This is the only document I've found that lets me manipulate an html contents file in my code.

However, I'm coming up a little short. On the setlabels, I have everything defined and working for tables. But I am also trying to reference a proc gchart procedure. When I run the code like I have for the tables, the contents page keeps the default name (HBar chart of Item) rather than the name I am assigning it with the setlabel.

Also, is it possible to remove the enumeration from the contents page?
SAS Super FREQ
Posts: 8,866

Re: RTF Table of contents

Hi:
To get rid of item numbers, in the TOC, you need a style template, as described in these Tech Support notes:
http://support.sas.com/kb/23/345.html
http://support.sas.com/kb/23/344.html

The reason the original questions (in the notes) were about HTML, is that you -do- see numbered contents items in the HTML TOC. But, when I get a TOC with RTF, I don't get numbers on the left in the TOC, (unless I put them in myself) so I'm not sure what enumeration you want to remove?? The page numbers that appear on the right?

I see what you mean about the GCHART, you're right, it doesn't seem to use the setlabel string in the TOC. It seems to use my DES= string:
[pre]
vbar age / discrete
des='Age';
[/pre]

So one workaround might be to use DES= for the string you want to see in the TOC. The description can be up to 256 characters.

You might want to work with Tech Support if you have more ODS DOCUMENT questions -- as the code can get quite lengthy and they have the most experience with ODS DOCUMENT.

cynthia
Contributor
Posts: 35

Re: RTF Table of contents

Posted in reply to Cynthia_sas
You sell yourself short Cynthia. All of your suggestions worked perfectly! I'm creating HTML output, so it was the numbered content on the left that I wanted to remove.

And since #Byval() is allowed in the DES=, I can still get unique labels which makes the workaround perfect for my uses.
SAS Super FREQ
Posts: 8,866

Re: RTF Table of contents

Hi:
Oh, somehow I missed that "HTML" for TOC results in the top of your other post. I somehow still had RTF firmly in mind.

I'm glad you got it going. I haven't played with ODS Document and Graph that much, so I'd never noticed that behavior of SETLABEL. That was a good lesson!

Thanks,
cynthia
Ask a Question
Discussion stats
  • 10 replies
  • 439 views
  • 0 likes
  • 5 in conversation