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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 3469 views
  • 3 likes
  • 3 in conversation