The SAS Output Delivery System and reporting techniques

Conditional formatting in proc report for a variable that is both numerical and categorical

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Conditional formatting in proc report for a variable that is both numerical and categorical

Is there a way to format data that looks like this:

 

P-Value

0.182

<0.001

0.002

 

I'd like to highlight any cells that have a p-value less than 0.05 and also highlight "<0.001'.

 

This works below, however I would like to avoid a copy/paste of the statements below and manually type in "0.002". Is there a way to also format for anything <0.05?

 

compute pvaluen2;

if pvaluen2 ="<0.001" then do;

call define(_col_,'style','style=[background=ltgray]');

end;

 


Accepted Solutions
Solution
‎08-16-2017 05:35 PM
Super User
Posts: 11,810

Re: Conditional formatting in proc report for a variable that is both numerical and categorical

Posted in reply to nirali514

Both of these are doable with custom formats.

 

proc format library=work;
value Pback
 low - <0.05= 'Red'
 ;
 value mypval
 low - <0.001 = '<0.001'
 other        = [best5.]
 ;
 run;

In the define block where you want the value highlight use the format instead of a color

 

style=[background= pback.]

if you want a different color when the the value is larger than 0.05 then add and "other" line to the pback format and the color desired.

And just use format=mypval. for the variable.

 

You can add as many color ranges as you would like but they cannot overlap. See the syntax for Proc Format on specifying ranges.

View solution in original post


All Replies
Contributor
Posts: 36

Re: Conditional formatting in proc report for a variable that is both numerical and categorical

Posted in reply to nirali514

Or if the data looks like this:

 

P-Value

0.182

0.00001

0.002

 

Is there a way to format highlightling for values <0.05 and also change 0.00001 to show "<0.001"

Solution
‎08-16-2017 05:35 PM
Super User
Posts: 11,810

Re: Conditional formatting in proc report for a variable that is both numerical and categorical

Posted in reply to nirali514

Both of these are doable with custom formats.

 

proc format library=work;
value Pback
 low - <0.05= 'Red'
 ;
 value mypval
 low - <0.001 = '<0.001'
 other        = [best5.]
 ;
 run;

In the define block where you want the value highlight use the format instead of a color

 

style=[background= pback.]

if you want a different color when the the value is larger than 0.05 then add and "other" line to the pback format and the color desired.

And just use format=mypval. for the variable.

 

You can add as many color ranges as you would like but they cannot overlap. See the syntax for Proc Format on specifying ranges.

Contributor
Posts: 36

Re: Conditional formatting in proc report for a variable that is both numerical and categorical

Thank you very much!! This worked
Super User
Posts: 10,210

Re: Conditional formatting in proc report for a variable that is both numerical and categorical

Posted in reply to nirali514
data x;
input pValue;
format pvalue pvalue12.3;
cards;
0.182
0.00001
0.002
;
run;




compute pvaluen2;
if pvaluen2 <0.001 then do;
call define(_col_,'style','style=[background=ltgray]');
end;

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 286 views
  • 0 likes
  • 3 in conversation