SAS9

Harmonizing the Style of Total Rows with Headers in PROC REPORT

Simon 7 vues

When creating reports with PROC REPORT, adding a summary line (grand total) is a common operation, usually performed via the RBREAK statement.

By default, this summary line adopts a standard style defined by the active ODS template (often a light gray or white background). However, for aesthetic or readability reasons, it is often desired that this total line looks exactly like the header row of the table (same background color, same bold font, same text color).

Harmonizing the Style of Total Rows with Headers in PROC REPORT -

The Laborious Approach: Hard-Coding

The natural first reaction is to open the ODS template's source code, identify the hexadecimal color codes for the header (e.g., cx112277 for the text and cxEDF2F9 for the background in the HTMLBlue style), and manually copy them into the statement.

SAS©
1
 
1/* À éviter : Code rigide et difficile à maintenir */
2rbreak after / summarize style=[fontweight=bold color=cx112277 backgroundcolor=cxEDF2F9];
3 
Although functional, this method is problematic: if you change the ODS style (e.g., from HTMLBlue to Plateau), your total line will not adapt and will retain the old colors, creating an inconsistent design.

The Elegant Solution: Style Inheritance

SAS© allows for direct referencing of existing style elements by their name, rather than redefining their attributes one by one. The style element that controls the appearance of column headers is simply named Header.

There are two simple ways to apply this style to your summary line.

Method 1: Local Application on the RBREAK Statement

This is the most precise method if you wish to target only the grand total generated by RBREAK.

1PROC REPORT DATA=sashelp.class;
2 columns sex weight;
3 define sex / group;
4 define weight / analysis mean f=5.2;
5
6 /* On applique directement le style 'Header' à la ligne de résumé */
7 rbreak after / summarize style=Header;
8RUN;

Method 2: Global Application via the STYLE Option

You can also define this behavior at the level of the PROC REPORT statement itself. This instructs the procedure to use the "Header" style for any element of type "summary".

1PROC REPORT DATA=sashelp.class style(summary)=Header;
2 columns sex weight;
3 define sex / group;
4 define weight / analysis mean f=5.2;
5
6 rbreak after / summarize;
7RUN;

Why Use This Method?

The main advantage is portability. By using style=Header, you are telling SAS©: "Regardless of the ODS template I use (PDF, HTML, RTF), make my total look like my headers". If you change the overall style of your report, the total line will automatically adapt without you needing to modify a single line of code.