sasods

SAS how to color specific rows with ODS and proc report


I plan to color some rows with specific conditions (male and name starts with 'J') in a table class:

ods excel close;
ods excel file='c://class.xlsx';
data class; set sashelp.class; 
  if substr(name,1,1)='J' and sex='M' then tt=1; 
run;
proc report data=class nowd;
 columns sex  height weight name age tt;
 compute tt;
  if tt=1 then call define(_row_, "style", "style=[backgroundcolor=yellow]");
 endcomp;
run;
ods _all_ close;

it does not work, and just wonder how to fix it?


Solution

  • Since you do not define tt, the default use will be a analysis column. Thus tt will not be available in the compute, instead it would be tt.<statistic>.

    Regardless, add a define statement to indicate tt is for display and the conditional styling will be applied correctly.

    proc report data=class ;
     columns sex  height weight name age tt;
    
     define tt / display;   /* explicitly specify column usage */
    
     compute tt;
      if tt=1 then call define(_row_, "style", "style=[backgroundcolor=yellow]");
     endcomp;
    run;
    

    enter image description here