BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

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.  

mcook_0-1664999946480.png

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.  

1 REPLY 1
ballardw
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 253 views
  • 0 likes
  • 2 in conversation