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 please help me fix this code as to why the 2nd record is not highlighted?

I want to highlight cell in column A when: A> 0 and B=1.

 

Thank you so much,

HHCFX

 


data have;
input n a b;
datalines;
1 2 .
2 3 1
3 0 1
4 -2 .
5 4 -1
;run;

proc report data=have nowd;
		define a/display;
		compute a  ;
		if a>0 and b=1 then call define(_col_,"style","style={background=light greenish yellow}");
		endcomp;
	run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

this should work

 

 

proc report data=have nowd;
			column n a b ;
			    define n/display;
				define a/display;
				define b/display;
				
                 compute  b;
					if a>0  and b=1 then do;		
			    do i = 2 to 3;
				call define(i, "style","style={background=light greenish yellow}");
				end;
				end;				
				endcomp;
		run;

 

 

 

 

 

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

this should work

 

 

proc report data=have nowd;
			column n a b ;
			    define n/display;
				define a/display;
				define b/display;
				
                 compute  b;
					if a>0  and b=1 then do;		
			    do i = 2 to 3;
				call define(i, "style","style={background=light greenish yellow}");
				end;
				end;				
				endcomp;
		run;

 

 

 

 

 

Cynthia_sas
Diamond | Level 26

Hi:

You have 2 issues:
1) not referenced B correctly. You either need to reference B.SUM in your IF statement or you need a DEFINE statement that defines B as DISPLAY usage
and
2) You cannot refer to B in the COMPUTE block for A. My guess is that the default order of variables is N, A and B. PROC REPORT has a left-to-right rule where, for example, if this is your COLUMN statement, either explicit or implicit:
column n a b;
you cannot refer to A or B in a compute block for N and you cannot refer to B in the compute block for A. PROC REPORT writes one report row at a time and writes one column at a time, working from left to right. So, at the point in time when REPORT puts N on the report row, it does not have any visibility of A or B and when REPORT puts A on the report row, there is no visibility of B yet. However, in a COMPUTE block for B you can test the values of N, A and B. You can also change N or A or B with a CALL DEFINE in the COMPUTE block for B, you just need the right syntax.

Are you getting error messages in the log or warnings when you run your existing code?

Cynthia

hhchenfx
Rhodochrosite | Level 12

Thank you for your help.

I learn a lot from the code and discussion.

HHCFX 

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
  • 1077 views
  • 1 like
  • 3 in conversation