Given a table such as
data Temp1;
input Col1 $4. Var1 Var2 Var3 Var4;
datalines;
Var1 . 45 200 223 11
Var2 0.43 . 43 99
Var3 0.98 0.89 . 39
Var4 0.99 0.77 0.99 .
;
run;
%LET FilePath=
C:\SamplePath\Folder1;
ODS RTF File="&FilePath.\ColorTest.Rtf";
ODS Escapechar='^';
options nonumber nodate;
proc report data=Temp1
style(Header)=[backgroundcolor = lightgrey];
columns Col1 Var1 Var2 Var3 Var4;
run;
ODS RTF close;
It ouputs the following rtf file, without the colors.
is it possible to add colors to certain cells based on the cell position, and not by its value?
ie. the cells below the diagonal for var2 x Var1, and Var4 x Var3 should always be yellow, regardless of their values. with the others cells being green.
Maybe not the most elegant but should get you started. Note the ADDED variable ROW.
data Temp1; input Col1 $4. Var1 Var2 Var3 Var4; row + 1; datalines; Var1 . 45 200 223 11 Var2 0.43 . 43 99 Var3 0.98 0.89 . 39 Var4 0.99 0.77 0.99 . ; run; proc report data=Temp1 style(Header)=[backgroundcolor = lightgrey]; columns row Col1 Var1 Var2 Var3 Var4; define row /noprint order; compute var1; if row=2 then call define(3, "style", "style=[backgroundcolor=yellow]"); if row in (3,4) then call define(3, "style", "style=[backgroundcolor=lightgreen]"); endcomp; run;
ROW has the NOPRINT property so it does not appear in the table but values can be checked in a compute block.
Note that call define is setting the number of the column based on the Columns statement definition. So the 3rd column is Var1 after Row and Col1.
And exercise for the interested student to do the columns for Var2, var3 and var4 as needed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.