BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chang
Quartz | Level 8

hi,

 

I would like to a RTF file with the table of contents, listing table titles, at page 1 and tables at the following pages. The table of contents inserts wrongly interted into the table body when the toc_data was specified, as can be seen in the following screenshot:

 

SAS_ODS_RTF_TOC_data.png

 

The wrongly displayed table of contents disappeared when the NOTOC_DATA option was specified instead of the TOC_DATA, as shown in this screenshot:

 

SAS_ODS_RTF_NOTOC_data.png

 

My questions:

  1. how do I correctly insert table titles in the table of content page?
  2. Is there an easy way to make the table autofit to content instead of manually specifying cell width of each column? Now I have specified cWide=25 pt (cellwidth) in the macro. An example of autofit to content:

SAS_ODS_RTF_NOTOC_data_autofit.png

 

 

My script files and data are attached:

  • NU_020_make_reports_master.sas is a master program where all the table files are excuted. To keep this example simple, I have just included one table. 
  • NU_021_table01.sas is the file where a table is created. This file reads data into SAS
  • def_display[1].sas contains a macro that writes the DEFINE statement in the REPORT procedure. This macro is called in the file NU_021_table01.sas
  • NU_021_table01.txt is the data (Tab-delimited txt) to be imported in SAS. NU_021_table01.sas reads this data.
  • Logo_of_the_QIMR_small.png is the logo that is displayed on the top left of every page in the report RTF. 

Thanks in advance!

Chang         

 

 


Logo_of_the_QIMR_small.png
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  When I use this code in SAS 9.4, Windows,

 

Here's my code:

ods rtf file='c:\temp\maketoc.rtf' toc_data contents=yes;
proc print data=sashelp.class;
  title 'SASHELP.CLASS';
run;
  
proc freq data=sashelp.class;
  tables age sex;
run;
  
proc print data=sashelp.classfit;
  title 'SASHELP.CLASSFIT';
run;
  
proc freq data=sashelp.classfit;
  tables age sex;
run;
  
ods rtf close;
title;

 

 

And here are results. First, if I click on the "Show/Hide" symbol on the ribbon, I can see the section break at the end of the first page. SAS only puts the field codes into the RTF file, you must manually cause Word (or your word processor of choice) to build the TOC from the field codes. After I click Show/Hide, this is what I see:

rtf_make_toc.jpg

 

Initially, when you look at the file after the Update Fields code, you will probably see the TOC and the field codes because the Show/Hide button is still active. But if you turn off the button, then the field codes are hidden again.

toc_on_sep_page.png

 

If you look closely at the first cell in the table, you can see that the whole field code is something like:

full_field_code.png

 

If you run my code and you DO get the same results that I show here, then there is something in your code that is causing the issue and you might want to open a track with Tech Support so they can look at your code and using your version of SAS and your operating system, see whether they can replicate the problem. If you run my code and you do NOT get the same results that I show here, then, that is also something that needs to be worked on with Tech Support. The Table of Contents in RTF has worked this way since SAS 9.2, so if my code does NOT work for you the same way that I illustrate in my screen shots, then something odd is happening.

 

cynthia

View solution in original post

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  When I use this code in SAS 9.4, Windows,

 

Here's my code:

ods rtf file='c:\temp\maketoc.rtf' toc_data contents=yes;
proc print data=sashelp.class;
  title 'SASHELP.CLASS';
run;
  
proc freq data=sashelp.class;
  tables age sex;
run;
  
proc print data=sashelp.classfit;
  title 'SASHELP.CLASSFIT';
run;
  
proc freq data=sashelp.classfit;
  tables age sex;
run;
  
ods rtf close;
title;

 

 

And here are results. First, if I click on the "Show/Hide" symbol on the ribbon, I can see the section break at the end of the first page. SAS only puts the field codes into the RTF file, you must manually cause Word (or your word processor of choice) to build the TOC from the field codes. After I click Show/Hide, this is what I see:

rtf_make_toc.jpg

 

Initially, when you look at the file after the Update Fields code, you will probably see the TOC and the field codes because the Show/Hide button is still active. But if you turn off the button, then the field codes are hidden again.

toc_on_sep_page.png

 

If you look closely at the first cell in the table, you can see that the whole field code is something like:

full_field_code.png

 

If you run my code and you DO get the same results that I show here, then there is something in your code that is causing the issue and you might want to open a track with Tech Support so they can look at your code and using your version of SAS and your operating system, see whether they can replicate the problem. If you run my code and you do NOT get the same results that I show here, then, that is also something that needs to be worked on with Tech Support. The Table of Contents in RTF has worked this way since SAS 9.2, so if my code does NOT work for you the same way that I illustrate in my screen shots, then something odd is happening.

 

cynthia

Cynthia_sas
SAS Super FREQ
Oh, forgot your #2 question, I do not believe there is a way to cause RTF to "autofit" the columns to the width of the cell contents.

cynthia
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I thikn you misunderstand what RTF is.  RTF is a text markup language - quite an old one and not being developed any more.  What you get out from your procedures is a text file which contains a whole set of control codes, and your text.  This file is then opened in a renderer - from your example I assume your using Word.  This renderer parses the text file and attempts to create an output representation based on the codes in the RTF.  Generally speaking this works reasonably well, however if your doing things like contents pages and such like your going to have difficulties all round - Word's TOC function didn't even exist when RTF was made.  

 

Can I ask wh you are building this in RTF?  Almost all Study outputs I have seen are created in this way:

- Create an RTF output from SAS for each individual output

- Build a PDF for a compete section be that Tables, Listings, or Figures

- Document builder teams then incorperate those into the main CSR's or other documents

Chang
Quartz | Level 8

hi RW9,

 

I am using a script file from someone else. Whatever can export TOC and tables to a WORD document would be good. For this purpose, which ODS do you recommend?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1263 views
  • 0 likes
  • 3 in conversation