SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

 

Hi Everyone,

Can you help me with this color code?

it works if I want to color '_c2_'.

Thank you,

HHCFX

 

data a;
input name $ v1 v2 v3;
datalines;
a 1 2 1
a 3 4 1
b 4 5 3
b 3 5 8
b 1 1 5
c 1 1 5
c 0 0 5
run;

proc report data=a nowd;

		define name/display;
		define v1/display;
		define v2/display;
		define v3/display;

		compute v1  ;
			if v1>2 then call define('_c3_',"style","style={background=BIYG}");
			else
			 call define('_c3_',"style","style={background=LIGY}");
			endcomp;
		run;

 

proc report data=a nowd;
		column name v1 v2 v3;
		define name/display;
		define v1/display;
		define v2/display;
		define v3/display;

compute v3  ;
			if v1>2 and 3<v2<=5 then call define(_col_,"style","style={background=BIYG}");
			else
			if v1>=1 and v2 <4 then call define(_col_,"style","style={background=LIGY}");
			endcomp;
run;  

 

SOLUTION 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
compute v3  ;
	if v1>2 then 
		call define(_col_,"style","style=[background=grey]");
	else
		call define(_col_,"style","style=[background=lightpink]");
endcomp;

You can reference a different variable in your logic. I think this works for what you want.

View solution in original post

4 REPLIES 4
Reeza
Super User
compute v3  ;
	if v1>2 then 
		call define(_col_,"style","style=[background=grey]");
	else
		call define(_col_,"style","style=[background=lightpink]");
endcomp;

You can reference a different variable in your logic. I think this works for what you want.

hhchenfx
Rhodochrosite | Level 12

  

Your code run. 

 

 

proc report data=a nowd;
		column name v1 v2 v3;
		define name/display;
		define v1/display;
		define v2/display;
		define v3/display;

compute v3  ;
			if v1>2 and 3<v2<=5 then call define(_col_,"style","style={background=BIYG}");
			else
			if v1>=1 and v2 <4 then call define(_col_,"style","style={background=LIGY}");
			endcomp;
run;  

 

Reeza
Super User
Works fine for me. Your second condition is never met though, is it? So there's a few records colored grey. I did remove the v4 because it just adds an empty column.
hhchenfx
Rhodochrosite | Level 12

Yes. Thank you.

My bad.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 4 replies
  • 813 views
  • 1 like
  • 2 in conversation