The SAS Output Delivery System and reporting techniques

Proc Report - coloring cell depending on value of other column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc Report - coloring cell depending on value of other column

Hello,
Basically I'm trying to color column cell using value of other column.
I would like to have all values of COL2 displayed colored where COL1='A'.
However, with following code only first value of COL2 where COL1='A' is being displayed colored.

Please suggest!!
Thanks!!


data test1;
  input COL1 $1. COL2 $5. NUM1;
datalines;
A rx1 2
A rx2 1
B rx1 1
B rx2 2
B rx2 5
B rx3 3
run;

ods pdf file="C:\test.pdf" notoc /*style=mystyle*/ uniform;

proc report data=test1 nofs nocenter headline headskip split="/" /*spanrows*/;
  column col1 col2 num1;

  define col1 / group;
  define col2 / group;
  define num1 / analysis sum;

  compute col2;   
if col1='A' then
  call define(_col_, "style", "STYLE=[BACKGROUND=cxFFFF82]");
  endcomp;
run;

ods pdf close;


Accepted Solutions
Solution
‎06-26-2013 10:18 AM
Respected Advisor
Posts: 3,775

Re: Proc Report - coloring cell depending on value of other column

You need to "remember" the value of col1.

proc report data=test1 nofs nocenter headline headskip split="/" /*spanrows*/;
  
column col1 col2 num1;
   define col1 / group;
  
define col2 / group;
  
define num1 / analysis sum;
  
compute before col1;
      col1r=col1;
     
endcomp;
  
compute col2;   
     
if col1r='A' then
         call define(_col_,
"style", "STYLE=[BACKGROUND=cxFFFF82]");
      endcomp;
  
run;

View solution in original post


All Replies
Solution
‎06-26-2013 10:18 AM
Respected Advisor
Posts: 3,775

Re: Proc Report - coloring cell depending on value of other column

You need to "remember" the value of col1.

proc report data=test1 nofs nocenter headline headskip split="/" /*spanrows*/;
  
column col1 col2 num1;
   define col1 / group;
  
define col2 / group;
  
define num1 / analysis sum;
  
compute before col1;
      col1r=col1;
     
endcomp;
  
compute col2;   
     
if col1r='A' then
         call define(_col_,
"style", "STYLE=[BACKGROUND=cxFFFF82]");
      endcomp;
  
run;
Occasional Contributor
Posts: 15

Re: Proc Report - coloring cell depending on value of other column

Excellnt, this works!

Thanks!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 230 views
  • 1 like
  • 2 in conversation