Consider the example here:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p14xegao6xt0xnn1865r422tpytw.htm
Under the heading, "Using a Format to Assign a Style Attribute Value", you'll see an example where cells are highlighted red if its value is negative.
How would I highlight the entire row as red if the value in the difference column were negative?
Taking this one step further: Can I make the selected row bold, red, and 18 pt, without having to use three separate formats (one for size, one for color, and one for font_weight?)
I can do this with PROC TEMPLATE using CELLSTYLE AS, but I can't find the solution for proc report. Possibly can I use PROC TEMPLATE on the template that PROC REPORT uses?
You can't use format to apply a style attribute to the entire row because a format is evaluated in each cell, so in order to apply a style attribute to an entire row, each cell in that row would need to have the same value.
data test;
input AFL $ BFL $ CFL $;
cards;
Y Y Y
Y N Y
N N N
;
proc format;
value $color
'Y' = 'green'
'N' = 'red';
run;
proc report data=test
style(column)={backgroundcolor=$color.};
run;
To apply a style attribute to an entire using the value of a specific variable, you need to use CALL DEFINE.
/*if using the already created format: $color */
proc report data=test;
compute CFL;
call define(_row_,'style',cats('style={backgroundcolor=',put(CFL,$color.),'}'));
endcomp;
run;
/*using conditional statements */
proc report data=test;
compute CFL;
if CFL = 'Y' then
call define(_row_,'style','style={backgroundcolor=green}');
else if CFL = 'Y' then
call define(_row_,'style','style={backgroundcolor=red}');
endcomp;
run;
The key is the _ROW_ automatic variable that indicates the entire current row.
You can't use format to apply a style attribute to the entire row because a format is evaluated in each cell, so in order to apply a style attribute to an entire row, each cell in that row would need to have the same value.
data test;
input AFL $ BFL $ CFL $;
cards;
Y Y Y
Y N Y
N N N
;
proc format;
value $color
'Y' = 'green'
'N' = 'red';
run;
proc report data=test
style(column)={backgroundcolor=$color.};
run;
To apply a style attribute to an entire using the value of a specific variable, you need to use CALL DEFINE.
/*if using the already created format: $color */
proc report data=test;
compute CFL;
call define(_row_,'style',cats('style={backgroundcolor=',put(CFL,$color.),'}'));
endcomp;
run;
/*using conditional statements */
proc report data=test;
compute CFL;
if CFL = 'Y' then
call define(_row_,'style','style={backgroundcolor=green}');
else if CFL = 'Y' then
call define(_row_,'style','style={backgroundcolor=red}');
endcomp;
run;
The key is the _ROW_ automatic variable that indicates the entire current row.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.