Hi:
Yes, you can do that kind of color coding. However, as Scott explained, you'd have to programmatically set the trafficlighting based on the ranking. This is the kind of task that is easy to do within a SAS macro program or just using SAS macro variables that were created before the PROC REPORT step. For example, look at step 8 in this paper:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
where the mean value is being determined with PROC SQL and put into a macro variable. Then the macro variable is used in a PROC REPORT. You may or may not need a macro program; however, you will have to look outside PROC REPORT to figure out the 2 highest & 2 lowest each time the report is run.
You would automatically capture the 2 highest and 2 lowest values every time you run your report and then use those values in your PROC REPORT program. In this case, I'd probably create 4 macro variables &HIGH1 and &HIGH2 for the 2 highest values and then &LOW1 and &LOW2 for the 2 lowest values. Then you could bypass the PROC FORMAT approach and directly code your COMPUTE block. This might be more straightforward than the PROC FORMAT approach, because you only have to create the macro variables and then use them in the CALL DEFINE logic, like this (in my example, HIGH = green and LOW= red):
[pre]
*** some procedure/program to create macro variables &HIGH1, &HIGH2, etc;
proc report ...;
column region product sales;
define sales /sum 'Sales';
compute sales;
if sales eq &high1 or sales eq &high2 then do;
call define(_COL_,'style','style={background=green}');
end;
else if sales eq &low1 or sales eq &low2 then do;
call define(_COL_,'style','style={background=red}');
end;
endcomp;
[/pre]
If (as your original post suggests) you have different criteria/coloring for different variables, you'd have to create multiple macro variables. For example if your variables are named NEW and OLD, you might need to make 4 macro variables for each variable:
&N_HI1, &N_HI2, &N_LO1, &N_LO2 (high and low for NEW var)
&O_HI1, &O_HI2, &O_LO1, &O_LO2 (high and low for OLD var)
and then you'd need a COMPUTE block for the NEW var with a CALL DEFINE and a COMPUTE block for the OLD var with a CALL DEFINE.
cynthia