/***************************************************************************************************************** SAS file name: One_Sample_tTest.sas File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to peform One sample t tests in SAS using PROC TTEST and PROC MEANS Author: Peter Clemmensen Creation Date: 18/03/2017 This program supports the example page "One Sample T Test in SAS" on SASnrd.com *****************************************************************************************************************/ /* Two Sided T Test */ proc ttest data=sashelp.class h0=60 sides=2 alpha=0.05; var height; ods output TTests=TTests; run; /* Save Statistics in macro variables */ data _null_; set TTests; call symputx('t',round(tValue, 0.01)); call symputx('p',round(Probt, 0.01)); call symputx('df',DF); run; /* Draw t distribution with critical areas shaded */ data t_curve; do x=-4 to 4 by 0.01; pdf=pdf('t', x, &DF); output; end; x=.;pdf=.; t = &t; t_pdf=pdf('t', &t, &df);output; t=.; t_pdf=.; do lower_x_band=-&t-3 to -&t by 0.01; lower_band=pdf('t', lower_x_band, &df); output; end; lower_x_band=.; lower_band=.; do upper_x_band=&t to &t+3 by 0.01; upper_band=pdf('t', upper_x_band, &df); output; end; upper_x_band=.; upper_band=.; run; title "t Distribution From Two Sided t Test"; title2 "With &df Degrees of Freedom and Critical Regions Shaded"; proc sgplot data=t_curve noautolegend; series x=x y=pdf / lineattrs=(color=black thickness=2) legendlabel="t(&DOF)"; dropline x = &t y = t_pdf / lineattrs = (color = black); dropline x = -&t y = t_pdf / lineattrs = (color = black); band x = lower_x_band upper = lower_band lower = 0 / fillattrs=(color=red); band x = upper_x_band upper = upper_band lower = 0 / fillattrs=(color=red); yaxis offsetmin=0 display=(nolabel); xaxis min=-3 max=3 label='x' labelattrs=(size=12 weight=Bold); run; title; /* One Sided T Test */ proc ttest data=sashelp.class h0=60 sides=u alpha=0.05; var height; run; title "t Distribution From One Sided t Test"; title2 "With &df Degrees of Freedom and Critical Region Shaded"; proc sgplot data=t_curve noautolegend; series x=x y=pdf / lineattrs=(color=black thickness=2) legendlabel="t(&DOF)"; dropline x = &t y = t_pdf / lineattrs = (color = black); band x = upper_x_band upper = upper_band lower = 0 / fillattrs=(color=red); yaxis offsetmin=0 display=(nolabel); xaxis min=-3 max=3 label='x' labelattrs=(size=12 weight=Bold); run; title;