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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
nirali514
Obsidian | Level 7

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"

ballardw
Super User

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.

Ksharp
Super User
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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 4 replies
  • 4476 views
  • 3 likes
  • 3 in conversation