I want to change the color of the header background and foreground for one value of the variables under the across variable (Cases Rate). I used a compute block to change the column background to light gray using the absolute column references _c4_ and _c5_. How do I change the header style attributes for _c4_ and _c5_, for example, to background=gainboro and foreground=black? I know I can change the color of the across variable header row (disease=cold) with a format, but what about the cells that read "Cases" and "Rates" under "Cold?" Version 9.3 or 9.4, using ODS PDF and proc report within ODS layout. Moving this question from stack overflow based on a suggestion from a user there that I might find an anwser here (Thanks Joe). A sample SAS Proc report code is below.
data test;
length name $ 10 disease $ 10.;
infile datalines dsd;
input name $ disease cases rate;
datalines;
State,Fever,4847,25.16
State,Cold,25632,131.5
State,Flu,103825,535.82
Lincoln,Fever,3920,44.17
Lincoln,Cold,16913,190.18
Lincoln,Flu,62965,735.39
Washington,Fever,827,56.56
Washington,Cold,3609,234.26
Washington,Flu,16610,1078.8
Kings,Fever,1026,37.45
Kings,Cold,4984,181.85
Kings,Flu,18388,694.33
Sussex,Fever,1411,78.38
Sussex,Cold,5515,300.46
Sussex,Flu,13881,813.11
Queens,Fever,616,26.03
Queens,Cold,2496,107.75
Queens,Flu,12518,558.09
;
run;
proc report data=test nowd headline headskip
STYLE(Header)={background=charcoal foreground=white }
style(column)={background=gray foreground=black}
style(report)=[rules=rows bordercolor=white];
columns (name disease,(cases rate));
define name/group order=data 'County' style(column)={background=lightgray} style(header)=[bordertopcolor=gainsboro background=gainsboro foreground=black];
define disease/across '' order=data ;
define cases/'Cases' format=comma9. ;
define rate/'Rate' format=comma12.1 ;
compute cases;
call define('_c4_','style','style={background=lighttgray}');
call define('_c5_','style','style={background=lightgray}');
endcomp;
run;
quit;
run;
Hi:
One method is described in this paper on actually using ACROSS variables to control the header color: http://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf
Another method is shown in the example below with user-defined formats:
Colors are a bit garish, I know, but you can see where every color is coming from in the code.
Hope this helps.
cynthia
Thanks Cynthia. I have several of your proc report papers. I think the format option would change all the headers that have the same value, correct? I want to change only one of the header columns, even though there are several that have the same value. The headers I want to change are highlighted below.
Hi
2 questions...
what is your destination of interest? RTF, PDF or HTML?
And, what do you actually want for the County column -- everything the same color for Header and the county values and then a different color above the County header in the empty cell?
cynthia
My destination is pdf, but I am also using ods layout to get other elements on the page. In terms of the color of the column headers, the same color as the column would be fine. I just want the colors to have a skip pattern like the columns themselves, to make it more readable.
I will look at the papers you suggest. Thanks again
Proc tabulate it is. I am using PROC REPORT LINE capability in several of the reports, but I can mix and match as needed. Thanks!
I would like to get an excel output working so that different across values are colored individually. I have attached an sample code on which I would like to color the var1 and var2 headers. I tried to follow Cynthia's instructions but couldn't get it working for some reason.
%let outputurl=;
proc format;
value $color "var1"='Gray'
"var2"='Yellow';
run;
data reportdata;
col1="var1";
col2="by1";
col3=1;
output;
col1="var1";
col2="by2";
col3=3;
output;
col1="var2";
col2="by1";
col3=9;
output;
col1="var2";
col2="by2";
col3=4;
output;
run;
data reportdata;
set reportdata;
dummy=1;
run;
/*options device=ACTXIMG;*/
/*ods excel file="&outputurl..xlsx"*/
/* options(sheet_interval="none" frozen_headers='2' frozen_rowheaders='1' gridlines='ON' */
/*orientattion='LANDSCAPE' suppress_bylines='ON' SHEET_NAME='Sheet1' autofilter='ALL');*/
proc report data=reportdata out=test;
col col1,(col2,col3) dummy;
define col1/across '' style(header)=Header{background=$color.};
define col2 /across '';
define col3/ '' nozero;
define dummy/noprint group;
run;
/*ods excel close;*/
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.