## 95% CI for means : direct output from proc means is different to calculated

Solved
Super Contributor
Posts: 325

# 95% CI for means : direct output from proc means is different to calculated

[ Edited ]

the author said that to get the 95% CI of the mean, it is the best to get N , Mean and Stdeer and use TINV function to calculate. This will get a narrower 95% CI for the mean compared to proc means or proc summary.

How did Proc Means or proc summary calculate the 95% CI for the mean?

In reality, which method is more often used?

``````*** three methods to get 95% CI for mean;

DATA test ;
INPUT subjno trt age ;
CARDS ;
1 1 25
2 2 30
3 1 15
4 1 45
5 2 22
6 2 54
;
RUN ;
PROC SORT DATA = test;
BY trt ;
RUN ;

*** method one: use proc means;

PROC MEANS DATA=test NOPRINT ;
BY trt ;
VAR age ;
OUTPUT OUT=xxtmp N=n MEAN=mean
STDERR=stderr LCLM=lclm Uclm=uclm ;
RUN ;

*** method two: use proc summary;

PROC SUMMARY DATA=test NOPRINT;
BY trt;
VAR age;
OUTPUT OUT=xxtmps N=n MEAN=mean
STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;

*** method three: use proc summary - this is the correct one;
PROC MEANS DATA=test NOPRINT;
BY trt ;
VAR age ;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean
STDERR=stderr LCLM=lclm UCLM=uclm ;
RUN ;

DATA xxtmp_2 ;
SET xxtmp_1;
lo = mean - ( TINV ( 0.95 , n-1 ) * stderr ) ;
hi = mean + ( TINV ( 0.95 , n-1 ) * stderr ) ;
RUN ;``````

Accepted Solutions
Solution
‎05-08-2017 04:21 PM
Super User
Posts: 20,688

## Re: 95% CI for means : direct output from proc means is different to calculated

I fixed it, but may have overridden yours.

Anyways, the paper is wrong - it's doing alpha=0.1 not alpha=0.05. The calculation happening is for a 90% confidence interval, not 95%.

Look at the 95% in the TINV function, for a two sided test it should 1-alpha/2 = 0.975 NOT 0.95. Once everything is the same the numbers from proc means match.

``````title 'method one: use proc means, alpha = 0.05, two sided test';

PROC MEANS DATA=sashelp.class n mean stderr lclm uclm alpha=0.05 vardef=df;
class sex;
VAR height;
OUTPUT OUT=xxtmp N=n MEAN=mean STDERR=stderr LCLM=lclm Uclm=uclm;
RUN;

*** method three: use proc summary - this is the correct one;

PROC MEANS DATA=sashelp.class noprint;
class sex;
VAR height;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;

DATA xxtmp_2;
SET xxtmp_1;
lo=mean - (TINV (0.975 , n-1) * stderr);
hi=mean + (TINV (0.975 , n-1) * stderr);
RUN;

title 'method two: use proc summary - this is the correct one';

proc print data=xxtmp_2;
run;``````

All Replies
Super User
Posts: 11,767

## Re: 95% CI for means : direct output from proc means is different to calculated

I wonder if this alternative is for a specific purpose but can't check as the link doesn't seem to work, at least for me.

Look in the online help for "Keywords and Formulas" in the SAS Elementary Statistic Procedures.

Super Contributor
Posts: 325

## Re: 95% CI for means : direct output from proc means is different to calculated

[ Edited ]

you can copy and paste the URL and it works.

Solution
‎05-08-2017 04:21 PM
Super User
Posts: 20,688

## Re: 95% CI for means : direct output from proc means is different to calculated

I fixed it, but may have overridden yours.

Anyways, the paper is wrong - it's doing alpha=0.1 not alpha=0.05. The calculation happening is for a 90% confidence interval, not 95%.

Look at the 95% in the TINV function, for a two sided test it should 1-alpha/2 = 0.975 NOT 0.95. Once everything is the same the numbers from proc means match.

``````title 'method one: use proc means, alpha = 0.05, two sided test';

PROC MEANS DATA=sashelp.class n mean stderr lclm uclm alpha=0.05 vardef=df;
class sex;
VAR height;
OUTPUT OUT=xxtmp N=n MEAN=mean STDERR=stderr LCLM=lclm Uclm=uclm;
RUN;

*** method three: use proc summary - this is the correct one;

PROC MEANS DATA=sashelp.class noprint;
class sex;
VAR height;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;

DATA xxtmp_2;
SET xxtmp_1;
lo=mean - (TINV (0.975 , n-1) * stderr);
hi=mean + (TINV (0.975 , n-1) * stderr);
RUN;

title 'method two: use proc summary - this is the correct one';

proc print data=xxtmp_2;
run;``````
Super Contributor
Posts: 325

## Re: 95% CI for means : direct output from proc means is different to calculated

[ Edited ]

Thank you for pointing out the mistake in the paper. Now I don't feel confused any more.

☑ This topic is solved.