BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello All,
Is there an option to insert headers and footers on every page of a multi page output using proc report.

Thanks,
Anita
4 REPLIES 4
Cynthia_sas
SAS Super FREQ
Hi, Anita:
As with all things ODS, "it depends". First, with ODS RTF, you can do this:
[pre]
ods rtf file='c:\temp\head_foot.rtf';

proc report data=sashelp.shoes nowd;
title 'SAS Title Goes into Header';
footnote 'SAS Footnote Goes into Footer';
where Region = 'Asia';
column region subsidiary product sales;
run;

proc freq data=sashelp.shoes;
table Region;
run;
ods rtf close;
[/pre]

and the SAS title and SAS footnote will be placed in the header and footer area of the RTF document. Note that the above technique has nothing to do with PROC REPORT. It is the SAS Title and Footnote statements that are working with RTF control strings. So, the technique will work with any procedure that sends output to ODS destinations -- not just PROC REPORT.

HTML and PDF output files do NOT have header and footer areas, like RTF output files. A SAS title or SAS footnote will go into the document at the appropriate place in the document. So, for PDF output from ODS, the SAS title and SAS footnote will appear on every page. For HTML output, the SAS title will appear at the top of the procedure output in the HTML file and the SAS footnote will be at the end of the procedure output in the HTML file. If the procedure produces HTML output that spans more than 1 printed page, then the SAS title is on printed page 1 and the SAS footnote is on the last printed page of the HTML file.

This syntax, using the TITLE= suboption, places a text string into the browser top navigation area (top browser title bar):
[pre]
ods html file='c:\temp\something.html' (title='HTML Title');
. . . SAS Code . . .
ods _all_ close;
[/pre]
With some browsers, this suboption MIGHT put the browser bar title "HTML Title" into the header area of the printed HTML file -- but this really is more dependent on the type of browser you are using and whether that browser has a printer interface that uses the browser bar title in this manner. Again, this is not procedure-dependent -- this capability is a feature of ODS that might be interpreted by a browser the way you want when the HTML file is printed (using the browser).

Since you asked specifically about PROC REPORT, there is, within PROC REPORT, the ability to write text to the output file (RTF, PDF or HTML) based on a COMPUTE BEFORE _PAGE_ or COMPUTE AFTER _PAGE_ block of code. However, if you use these kinds of compute blocks to write text, the text goes into the document itself, (and if you're creating RTF -- this means NOT in the header/footer area) If you knew RTF control string syntax, you might be able to write some code that would go into the Header area of the RTF file, but since the SAS title will go there automatically, that seems the easiest way to go with RTF.

Let's say you wanted to do a report for every Region and that you wanted the Region name to be in the header area of the resulting RTF document. Rather than using PROC REPORT capabilities, you might consider using BYGROUP processing like this:
[pre]
option nobyline;
ods rtf file='c:\temp\head_foot_by.rtf';

proc report data=sashelp.shoes nowd;
title 'SAS Title Goes into Header';
title2 'For #byval(region)';
footnote 'SAS Footnote Goes into Footer';
by Region;
where Region = 'Asia' or Region = 'Canada';
column region subsidiary product sales;
run;

ods rtf close;
options byline;
title; footnote;
[/pre]

When SAS encounters the #byval(region) reference, it substitutes the value of the current BYGroup value into the SAS title. If you are creating RTF output, then this information goes into the header area of the RTF output file.

If you need to create an output file other than RTF or HTML, then, there is only one other ODS destination that puts information into a "header" area. That is TAGSETS.EXCELXP -- by default, it places the SAS Title into the Header area of the Excel Workbook and the SAS Footnote into the Footer area of the Excel Workbook. Again, this capability has nothing to do with a specific procedure, but is the default way that the ExcelXP tagset treats the SAS title unless you do something other than the default.

cynthia
deleted_user
Not applicable
Thanks cynthia.
But what if we are using macros to write the header and footer on every table. Where do we specify these ODS conditions on the initiation prg or macro prg or the template used to create the listing.

Thanks in advance.
Cynthia_sas
SAS Super FREQ
Hi!
Are you using SAS macro programs or Word macros??? If the macro programs are SAS macro programs, then are they writing RTF control strings WITHOUT using ODS?? Or are they writing RTF control strings WITH ODS?

The information I gave you is still correct. By default, the SAS title goes into the Header area of a Word document and the SAS footnote goes into the Footer area of a Word document. This is different than putting a TABLE header or TABLE footer on EVERY table. Depending on whether you are using BY group processing or not, either COMPUTE BEFORE or COMPUTE BEFORE _PAGE_ might be used to put a TABLE header above a TABLE and a TABLE footer below a TABLE.

This question is probably better handled by Tech Support, as they can look at EXACTLY what your original program is doing and tell you how to change it to achieve your desired results.

cynthia
Duong
Obsidian | Level 7
Hi Both

I assume you are using the RTF destination. If so you can do the following:


Method 1 – with the bodytitle option
Then post-process your RTF file to add in the header/footer text.
Search your RTF file (look around the header/footer string) to add in header and footer text.

Method 2 - without the bodytitle option
Use the title and footnote statements for your header/footer text. Then use the compute block for your titles and footnotes text. I have not tried this though.


BUT I believe text from title/footnote statements should go to the body of the table so preferred to use method 1.

SAS now have the headery and footery options for the header/footer offsets so we might see the text option for this in future release.


Duong

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 10960 views
  • 1 like
  • 3 in conversation