/**Normal Confidence Interval for the Mean **/ /*********************************************************** Macro nint1 does 1 sample normal confidence interval for the Mean. INPUT: dataset: input data set variable: variable to be analyzed sigma: population standard deviation level: confidence level OUTPUT: sample mean and confidence interval ***********************************************************/ %macro nint1(dataset,variable,sigma,level); %let alpha2=%sysevalf((1+&level)/2); %let sig=%sysevalf(&sigma); proc summary data=&dataset; var &variable; output out=z_out n=n mean=mean; run; data z_out; set z_out; zquant=probit(&alpha2); moe=&sig/sqrt(n); LCL=mean-zquant*moe; UCL=mean+zquant*moe; run; proc print noobs; var mean LCL UCL; run; %mend nint1; /*********************************************************** Sample call: data ldl; input decrease_ldl @@; cards; -7.6 13.9 27.1 14.8 6.3 42.0 41.7 18.5 31.2 24.0 ; run; %nint1(ldl,decrease_ldl,16.,.95); ***********************************************************/ /**t Confidence Interval for the Mean **/ /*********************************************************** Macro tint1 does 1 sample t confidence interval for the Mean. INPUT: dataset: input data set variable: variable to be analyzed level: confidence level OUTPUT: sample mean and confidence interval sample std dev and confidence interval ***********************************************************/ %macro tint1(dataset,variable,level); %let alpha2=%sysevalf(1-&level); proc ttest data=&dataset sides=2 alpha=&alpha2; var &variable; ods select conflimits; run; %mend tint1; /*********************************************************** Sample call: data ldl; input decrease_ldl @@; cards; -7.6 13.9 27.1 14.8 6.3 42.0 41.7 18.5 31.2 24.0 ; run; %tint1(ldl,decrease_ldl,.95); ***********************************************************/ /** Approximate Score (Agresti-Coull) Confidence Interval for a Proportion **/ data ldl; input decrease_ldl @@; decrease=(decrease_ldl>0); cards; -7.6 13.9 27.1 14.8 6.3 42.0 41.7 18.5 31.2 24.0 ; run; proc sort data=ldl; by descending decrease; run; proc print;run; proc freq data=ldl order=data; tables decrease/binomial(ac) alpha=.05; run; /** Two-Sample t Confidence Intervals **/ /*********************************************************** Data are found in sasdata.blades2 ***********************************************************/ proc ttest data=sasdata.blades2 alpha=.1; class manufacturer; var y; run; /** Two-Sample Approximate Score (Agresti-Coull) Confidence Interval **/ /******************************************** Macro to compute two-sample approximate score (Agresti-Coull) confidence interval. INPUT: o y1,y2: number having characteristic in samples 1 and 2 o n1,n2: sample size, samples 1 and 2 o conf_level: desired confidence level OUTPUT: o Point estimate of p1-p2 o Approximate score CI for p1-p2 *********************************************/ %macro ac2(y1,n1,y2,n2,conf_level); data ac2; tail_area=(1+&conf_level)/2; z=probit(tail_area); p1hat=&y1/&n1; p2hat=&y2/&n2; point_est=p1hat-p2hat; n1_tilde=&n1+.5*z**2; n2_tilde=&n2+.5*z**2; p1_tilde=(&y1+.25*z**2)/n1_tilde; p2_tilde=(&y2+.25*z**2)/n2_tilde; se=sqrt(p1_tilde*(1-p1_tilde)/n1_tilde+p2_tilde*(1-p2_tilde)/n2_tilde); ci_low=p1_tilde-p2_tilde-z*se; ci_up=p1_tilde-p2_tilde+z*se; run; proc print noobs; var point_est ci_low ci_up; run; %mend ac2; /******************************************** Sample call using numbers from example in lecture notes: %ac2(24,200,26,100,.95); *********************************************/