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;
@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 🙂
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 😞
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;
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
@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 🙂
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.