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

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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