The SAS Output Delivery System and reporting techniques

Highlight one column with two different colors

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Highlight one column with two different colors

 How two highlight the Age column  with different colors.

 

 

ods tagsets.excelxp file="bylines.xls" style=statistical

options( suppress_bylines='yes' sheet_interval='none' );

proc report data=sashelp.class nowd;

column name age sex height weight ;

define name / display;

define age / display;

define sex / order;

define height / display;

define weight / display;

 

 

compute AGE;

if (height=50 AND weight<60) then call define(_col_,"style","style={background=blue}");

if (height <60 AND weight >60) then call define(_col_,"style","style={background=red}");

endcomp;

run;

ods _all_ close;


Accepted Solutions
Solution
‎12-20-2016 10:09 AM
Super User
Posts: 19,772

Re: Highlight one column with two different colors


tekish wrote:
It works fine.
Thanks.

Awesome. Please mark the question solved. 

 

@Cynthia_sas Thanks for the explanation. It's one of those things I know but never remember the details of why Smiley Happy

View solution in original post


All Replies
Super User
Posts: 19,772

Re: Highlight one column with two different colors

Your first condition is never met with the SASHELP.CLASS dataset.

I don't actually see anything else incorrect with your code...but it doesn't work for me either Smiley Sad

Super User
Posts: 19,772

Re: Highlight one column with two different colors

It's an order of columns issue. Proc Report has some weird rules about the order of variable usage. If you use the compute weight and explicitly reference the age column it works fine.

 

compute weight;
if height>60 and weight>60 then call define("age", 'style', 'style=[background=blue]');
else if height<60 and weight>60 then call define("age", 'style', 'style=[background=red]'); 
endcomp;
SAS Super FREQ
Posts: 8,864

Re: Highlight one column with two different colors

[ Edited ]

Good job Reeza! It didn't work in the COMPUTE block for age because PROC REPORT has this "weird" left-to-right rule. In the original COLUMN statement:
column name age sex height weight ;
PROC REPORT builds the report row one cell at a time -- working from the left of the column statement and moving to the right. So at the point in time when PROC REPORT is holding the value of AGE on the report row, it does not yet know the values for HEIGHT or WEIGHT.

So the COMPUTE block for AGE cannot test HEIGHT or WEIGHT. But by the time PROC REPORT is writing WEIGHT on the report row, there is visibility of all the variable values to the "left" of WEIGHT on the report row. So in the COMPUTE block for WEIGHT, all the rest of the variable values can be tested.

cynthia

Contributor
Posts: 53

Re: Highlight one column with two different colors

Posted in reply to Cynthia_sas
It works fine.
Thanks.
Solution
‎12-20-2016 10:09 AM
Super User
Posts: 19,772

Re: Highlight one column with two different colors


tekish wrote:
It works fine.
Thanks.

Awesome. Please mark the question solved. 

 

@Cynthia_sas Thanks for the explanation. It's one of those things I know but never remember the details of why Smiley Happy

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 375 views
  • 2 likes
  • 3 in conversation