BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cklager44
Fluorite | Level 6

I want to output to Word standard headers and footers on every page that give the project title, the page number, etc., and then also a title directly above each table.

 

When I want the table to look like this:

 

Table 1: Sample Table Title

Table 1 Undertitle: Population

followed by a table, with a header row like:

Variable Name, % (n/N)

and content rows like:

Variable 1, 1.0% (1/100)

Variable 2, 0.0% (0/100)

...

Variable 45, 10.0% (10/100)

 

...I achieve it with this code:

 

ods rtf file="&outputfile..rtf";

title j=l h=9pt "Company Name"  j=c "Confidential" j=r "Company Logo";

footnote j=l h=9pt "Created by cklager44" j=r "Page (*ESC*){pageof}";

 

*title for table of contents;

ods proctable="title_name";

 

*title for table;

ods rtf text="(*ESC*)S={font_weight=bold just=c}Table 1: Sample Table Title";

ods rtf text="(*ESC*)S={font_weight=bold just=c}Table 1 Undertitle: Population";

 

proc report;

compute after _page_;

    line "Note: add table footnotes to the end of the table here.";

endcomp;

ods rtf close;

 

Here is my problem! The ORS RTF TEXT becomes part of the table, as far as Word is concerned. I want to have the header row ("Variable Name, % (n/N)") repeat at the top of each page when the table spans multiple pages. I do NOT want to have "Table 1: Title" and "Table 1 Undertitle" repeat. But since Word considers those 2 titles as the first 2 rows of the table, any repeating must include those two rows.

 

I am open to rethinking the entire method I use to create titles in my documents, if it means I can automate having repeating headers in the table the way I want. Thanks.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Me too. I am not sure I fully follow your question.  Can you post a snapshot or picture to illustrate your question ?

According to what I understand, I think there are THREE ways you could try:

 

1)


title;
options nocenter nodate nonumber;
ods tagsets.rtf file='c:\temp\test.rtf' style=journal startpage=no
  options(tables_off='usertext'  vspace="no"  continue_tag = "no"); *tables_off = "systitleandfootercontainer";
ods tagsets.rtf text='(*ESC*){style [fontsize=50] xxxxxxxx}' ;  
proc report data=sashelp.heart(obs=50) nowd;
column sex status height weight;
run;
ods tagsets.rtf close;

Ksharp_0-1768479257955.png

Ksharp_1-1768479286756.png

 

 

2)

title;
options nocenter nodate nonumber;
ods tagsets.rtf_sample file='c:\temp\test.rtf' style=journal startpage=no
  options(tables_off='usertext'  vspace="no"  continue_tag = "no"); *tables_off = "systitleandfootercontainer";
ods tagsets.rtf_sample text='(*ESC*){style [fontsize=50] xxxxxxxx}' ;  
proc report data=sashelp.heart(obs=50) nowd;
column sex status height weight;
run;
ods tagsets.rtf_sample close;

 

3)

ods rtf file = "c:\temp\test-run.rtf"  style = journal ;
title;
footnote;

proc report data=sashelp.heart(obs=50) nowd  style={pretext='YYYYYYYYY' fontsize=4};
column sex status height weight;
run;

ods rtf close;

Ksharp_2-1768479602272.png

 

 

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

Do you have multiple tables on one page? If not then just use TITLE2 and TITLE3 for the sub titles.

cklager44
Fluorite | Level 6

@Tom wrote:

Do you have multiple tables on one page? If not then just use TITLE2 and TITLE3 for the sub titles.


This will not work. The TITLE appears in the header of the document, but the ODS RTF TEXT (the actual table title) appears in the body of the document immediately above the table. If I put the table titles in TITLE2 / TITLE3, they would appear in the header area, which would not work for me. If I use BODYTITLE, then the actual header information that I want in the header would appear in the body, and that would not work for me.

Tom
Super User Tom
Super User

You might try ODS WORD instead.

Screenshot 2026-01-15 at 4.34.40 PM.png

ods rtf file = "~/rtf_sample.rtf"  style = journal ;
ods word file = '~/word_sample.docx' style=journal ;
title1 'Run in SAS ODA';
title2 'Open destinations';
proc print data=sashelp.vdest; run;
title2 'SASHELP.CLASS';
proc print data=sashelp.class; 
run;
title2 'SASHELP.CARS';
proc print data=sashelp.cars(obs=60);
  var make -- invoice;
run;
ods word close;å
ods rtf close;
Kathryn_SAS
SAS Employee

I am not sure I fully understand, but you may want to consider using the Tagsets.RTF_Sample destination where you can use the SPANROWS option in PROC REPORT to repeat Group or Order variables than span multiple pages.

ods listing close;
ods tagsets.rtf_sample file="c:\temp\test.rtf";

title j=l h=9pt "Company Name"  j=c "Confidential" j=r "Company Logo";
footnote j=l h=9pt "Created by cklager44" j=r "Page (*ESC*){pageof}";

ods proclabel "title_name";

ods tagsets.rtf_sample text="(*ESC*)S={font_weight=bold just=c}Table 1: Sample Table Title";
ods tagsets.rtf_sample text="(*ESC*)S={font_weight=bold just=c}Table 1 Undertitle: Population";

proc report data=sashelp.cars(obs=100) spanrows;
column make model type origin;
define make / order;
compute after _page_;
    line "Note: add table footnotes to the end of the table here.";
endcomp;
run;

ods tagsets.rtf_sample close;
ods listing;

If you have additional questions, please send a sample of the output and clarify the changes you are expecting.

Ksharp
Super User

Me too. I am not sure I fully follow your question.  Can you post a snapshot or picture to illustrate your question ?

According to what I understand, I think there are THREE ways you could try:

 

1)


title;
options nocenter nodate nonumber;
ods tagsets.rtf file='c:\temp\test.rtf' style=journal startpage=no
  options(tables_off='usertext'  vspace="no"  continue_tag = "no"); *tables_off = "systitleandfootercontainer";
ods tagsets.rtf text='(*ESC*){style [fontsize=50] xxxxxxxx}' ;  
proc report data=sashelp.heart(obs=50) nowd;
column sex status height weight;
run;
ods tagsets.rtf close;

Ksharp_0-1768479257955.png

Ksharp_1-1768479286756.png

 

 

2)

title;
options nocenter nodate nonumber;
ods tagsets.rtf_sample file='c:\temp\test.rtf' style=journal startpage=no
  options(tables_off='usertext'  vspace="no"  continue_tag = "no"); *tables_off = "systitleandfootercontainer";
ods tagsets.rtf_sample text='(*ESC*){style [fontsize=50] xxxxxxxx}' ;  
proc report data=sashelp.heart(obs=50) nowd;
column sex status height weight;
run;
ods tagsets.rtf_sample close;

 

3)

ods rtf file = "c:\temp\test-run.rtf"  style = journal ;
title;
footnote;

proc report data=sashelp.heart(obs=50) nowd  style={pretext='YYYYYYYYY' fontsize=4};
column sex status height weight;
run;

ods rtf close;

Ksharp_2-1768479602272.png

 

 

cklager44
Fluorite | Level 6

I attached an example image.

In the example, "Company Name - Confidential - Data Snapshot Date" is created by a TITLE statement.

"Table 1: Title" and "Table 1: Undertitle" (created by ODS RTF TEXT statements) are considered by Word to be part of the table underneath it (created by proc report).

 

In my example, there are only 4 rows, but if there are 25+ rows, the table would span multiple pages.

 

The built in / default option in Word to repeat header rows requires you start at row one and pick how many rows you want to be part of header. The problem is, I want only what Word sees as row 3 to repeat/span multiple pages. Row 3 is (to me) the table header. The title/undertitle I do not want to repeat.

 

I will try the methods suggested and get back to you.

 

cklager44
Fluorite | Level 6

Option 3 was very easy to implement and works perfectly.

Thanks

 

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1570 views
  • 4 likes
  • 4 in conversation