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 🙂
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: