BookmarkSubscribeRSS Feed

Set a background color for spanned header in PROC REPORT: ODS Excel destination

Started ‎03-22-2024 by
Modified ‎03-26-2024 by
Views 618

When you write PROC REPORT output to ODS destinations, you can add colors and other style attributes to headers, including column headers and spanning headers. For individual column headers, all destinations honor the background and foreground colors, as shown below. However, for spanning headers, the Excel destination does not apply the background color to the spanning header as you would expect. The sample code below illustrates this issue, and the resulting Excel and RTF output are provided.

 

ods _all_ close;
ods escapechar='^';
ods excel file='test.xlsx';
ods rtf file='test.rtf';

proc report data=sashelp.class
 style(column)=[cellwidth=1in];
where age le 13;
column sex age 
 ('^S={background=green foreground=orange} Statistics' height weight);
define age / group 'how old are you?'
 style(header)=[background=yellow foreground=red];
define sex / group 'gender';
define height / mean 'average height' format=8.2;
define weight / mean 'average weight' format=8.2;
run;

ods _all_ close;
ods listing;
 
 

RTF output (looks as expected):

Kathryn_SAS_2-1711125710267.png

 

Excel output (background color missing!):

Kathryn_SAS_4-1711125750818.png

Don’t worry! You can get a spanning header with a background color in the Excel destination by adding a character variable to the data set that contains the text of the desired spanning header. You can then use this variable as an ACROSS variable and apply the background color to that variable.

 

data class;
set sashelp.class;
hdr='Statistics';
run;

ods _all_ close;
ods escapechar='^';
ods excel file='test1.xlsx';

proc report data=class
 style(column)=[cellwidth=1in];
where age le 13;
column sex age hdr,(height weight);
define hdr / across ' ' style=[background=green foreground=orange];
define age / group 'how old are you?'
 style(header)=[background=yellow foreground=red];
define sex / group 'gender';
define height / mean 'average height' format=8.2;
define weight / mean 'average weight' format=8.2;
run;

ods _all_ close;
ods listing;

 

Excel output (now correct!):

Kathryn_SAS_5-1711125925965.png

That’s all there is to it! Now the spanning header contains the desired background color in your Excel table.

 

Learn more about PROC REPORT from Jane Eslinger's book: The SAS Programmer's PROC REPORT Handbook

Version history
Last update:
‎03-26-2024 11:17 AM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags