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

Hi, I want to format p in the macro below so that I can report the exact p-value. I tried using the bestd32.31 format but still get a p rounded as 0. Any help would be much appreciated. Thanks!

 

%macro combchi(df=,chi=);
proc iml;
df=&df;
g2={&chi};
m=ncol(g2);
g=sqrt(g2);
mg2=sum(g2)/m;
r=(1+1/m)*(ssq(g)-(sum(g)**2)/m)/(m-1);
f=(mg2/df - r*(m-1)/(m+1))/(1+r);
ddf=(m-1)*(1+1/r)**2/df**(3/m);
p=1-probf(f,df,ddf);
print f df ddf;
print p[format=bestd32.31];
quit;
%mend combchi;

 

%combchi(df=2,chi=102.997006 108.592438 105.224443 111.206028 106.644927)

 

SAS Output:

The SAS System

f df ddf
52.00922823641.6389

p
0
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The problem is not the format, it is the way you are computing the p-value.  When you compute the quantity 

p = 1 - probf(...);

the PROBF function computes the left tail of the F distribution and returns 1 to within numerical precision. When you want an extreme p-value, it is more accurate numerically to compute the RIGHT tail directly by using the SDF function:

p = sdf("F", f,df,ddf);

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The problem is not the format, it is the way you are computing the p-value.  When you compute the quantity 

p = 1 - probf(...);

the PROBF function computes the left tail of the F distribution and returns 1 to within numerical precision. When you want an extreme p-value, it is more accurate numerically to compute the RIGHT tail directly by using the SDF function:

p = sdf("F", f,df,ddf);

 

ballardw
Super User

You might also want to consider using the PVALUEw.d format.

 


@greveam wrote:

Hi, I want to format p in the macro below so that I can report the exact p-value. I tried using the bestd32.31 format but still get a p rounded as 0. Any help would be much appreciated. Thanks!

31 decimal places is still likely not "the exact p-value". It is the value displayed to a precision of 31 decimals. Though when fewer digits are shown it could be the result of another rounding/truncation/precision issue in the calculations involved.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1288 views
  • 2 likes
  • 3 in conversation