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.

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