BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sascom10
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

2 REPLIES 2
data_null__
Jade | Level 19

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;
sascom10
Calcite | Level 5

Excellnt, this works!

Thanks!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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