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,

 

I want to put color code on my column Name and it doesn't work correctly even though it pain color correctly if I paint other column.

 

Can you help me with the logic here?

 

Thanks.

 

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;


*USING V2 or V3 in COMPUTE work correctly;

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 name^=lag(name) then call define(_col_,"style","style={background=BIYG}");
			else
			if v2 <3 then call define(_col_,"style","style={background=YELLOW}");
			endcomp;
run;

*USING NAME  in COMPUTE --> NOT correctly;

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

compute NAME  ;
			if name^=lag(name) then call define(_col_,"style","style={background=BIYG}");
			else
			if v2 <3 then call define(_col_,"style","style={background=YELLOW}");
			endcomp;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Proc report builds a table from left to right. You cant reference any variable that appears to the right of the current column in a calculation.

So  since both V2 and V3 appear to the right of Name in column heading they are not available to use in computation for the NAME cells.

compute NAME  ;
	if name^=lag(name) then call define(_col_,"style","style={background=BIYG}");
	else
	if v2 <3 then call define(_col_,"style","style={background=YELLOW}");
endcomp;

One approach would be add a variable that indicates the v2<v3 status, include it BEFORE name on the column statement and set it to NOPRINT so it does not appear in the output but is available for use in the NAME compute block.

 

View solution in original post

3 REPLIES 3
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

this may help you I have copied it from another solution

http://support.sas.com/resources/papers/proceedings11/290-2011.pdf

 

ballardw
Super User

Proc report builds a table from left to right. You cant reference any variable that appears to the right of the current column in a calculation.

So  since both V2 and V3 appear to the right of Name in column heading they are not available to use in computation for the NAME cells.

compute NAME  ;
	if name^=lag(name) then call define(_col_,"style","style={background=BIYG}");
	else
	if v2 <3 then call define(_col_,"style","style={background=YELLOW}");
endcomp;

One approach would be add a variable that indicates the v2<v3 status, include it BEFORE name on the column statement and set it to NOPRINT so it does not appear in the output but is available for use in the NAME compute block.

 

hhchenfx
Rhodochrosite | Level 12

oh I see.

Thanks a lot.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1251 views
  • 0 likes
  • 3 in conversation