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.
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.
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.