BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mftuchman
Quartz | Level 8

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?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Athenkosi
Obsidian | Level 7

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;

Capture.PNG

 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;

Capture.PNG

 The key is the _ROW_ automatic variable that indicates the entire current row.

 

 

 

View solution in original post

2 REPLIES 2
Athenkosi
Obsidian | Level 7

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;

Capture.PNG

 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;

Capture.PNG

 The key is the _ROW_ automatic variable that indicates the entire current row.

 

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 820 views
  • 1 like
  • 2 in conversation