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

In this paper http://www.lexjansen.com/pharmasug/2003/Posters/P048.pdf

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 ;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

6 REPLIES 6
ballardw
Super User

I get a "not found" error for your link.

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.

fengyuwuzu
Pyrite | Level 9

you can copy and paste the URL and it works.

I just fixed the link

Reeza
Super User

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;
fengyuwuzu
Pyrite | Level 9

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

Suki99
Fluorite | Level 6

The reply is strictly speaking still incorrect in the code , as you state your going to use proc summary, but in fact you've repeated proc means twice.

Reeza
Super User

@Suki99 wrote:

The reply is strictly speaking still incorrect in the code , as you state your going to use proc summary, but in fact you've repeated proc means twice.


PROC MEANS and SUMMARY are interchangeable in this context. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 43044 views
  • 3 likes
  • 4 in conversation