/*SPECIFY GENERIC OUTPUT USING OPTIONS FORMCHAR= */ options formchar="|----|+|---+=|-/\<>*"; /*READ IN THE RAW DATA. SET UP VARIABLE LABELS.*/ data pulse; infile "pulse.csv" firstobs=2 delimiter="," missover; input pulse1 pulse2 ran smokes sex height weight activity; label pulse1 = "Resting pulse, rate per minute" pulse2 = "Second pulse, rate per minute"; run; /*PRINT OUT THE FIRST 25 CASES*/ proc print data=pulse (obs=25); run; /*CREATE TEMPORARY FORMATS AND ASSIGN FORMATS TO CORRESPONDING VARIABLES*/ proc format; value sexfmt 1="Male" 2="Female"; value yesnofmt 1="Yes" 2="No"; value actfmt 1="Low" 2="Medium" 3="High"; run; proc print data=pulse (obs=25) label; format sex sexfmt. ran smokes yesnofmt. activity actfmt.; run; /*DISPLAY DATA FILE INFORMATION AND VARIABLE LISTS */ proc contents data=pulse varnum; run; /*OBTAIN DESCRIPTIVE STATISTICS */ proc means data=pulse; run; /*Binomial Test*/ proc freq data = pulse; tables smokes / binomial(p=.25); run; proc freq data = pulse; tables smokes / binomial(p=.25); exact binomial; run; /*Chisquare goodness of Fit tests*/ /*Assume equal proportions in each category*/ proc freq data = pulse; tables activity / chisq; run; /*Provide hypothesized proportions, based on prior data*/ proc freq data = pulse; tables activity /chisq testp = ( .20 , .50, .30 ); run; /*ONE-SAMPLE T TEST*/ proc univariate data=pulse mu0=72; var pulse1; histogram / normal (mu=est sigma=est); qqplot /normal (mu=est sigma=est); run; proc ttest data=pulse H0=72 ; var pulse1; run; /*Chisquare test of independence*/ proc freq data=pulse; tables sex*smokes / chisq; run; proc freq data = pulse; tables sex * activity / chisq expected nocol nopercent; run; /*SAME TEST, BUT FOR NON-SMOKERS ONLY*/ proc freq data=pulse; tables sex * activity /nopercent nocol expected chisq; where smokes=2; run; /*FOR TABLES CONTAINING SPARSE CELLS, FISHER'S EXACT TEST CAN BE PERFORMED */ proc freq data=pulse; tables sex * activity /nopercent nocol; exact fisher; where smokes=2; run; /*Monte Carlo Simulation of Exact Probability*/ proc freq data = pulse; where smokes=2; tables sex * activity / chisq expected; exact fisher / mc seed=1234; run; /*Q-Q PLOT CAN BE USED TO CHECK NORMALITY ASSUMPTION OF TEST VARIABLES, AT EACH LEVEL OF THE GROUPING VARIABLE */ proc sort data=pulse; by ran; run; proc univariate data=pulse; by ran; var pulse2; histogram / normal; qqplot /normal (mu=est sigma=est); run; /*BOXPLOT ALLOWS YOU TO COMPARE THE TEST VARIABLES VISUALLY BETWEEN TWO GROUPS, FOR BOTH LOCATION AND SPREAD */ proc sort data=pulse; by ran; run; proc boxplot data=pulse; plot (pulse1 pulse2) * ran; run; /*INDEPENDENT SAMPLES T TEST*/ proc ttest data=pulse; var pulse1 pulse2; class ran; run; /*NON-PARAMETRIC TEST: WILCOXON/MANN-WHITNEY TEST*/ proc npar1way data=pulse wilcoxon; class ran; var pulse1 pulse2; run; /*Use the Exact Statement to get Monte Carlo Simulation for estimateion of Exact p-value*/ proc npar1way data=pulse wilcoxon; class ran; var pulse1 pulse2; exact wilcoxon / mc; run; /*PAIRED SAMPLES TESTS*/ proc corr data=pulse; var pulse1 pulse2; run; proc ttest data=pulse; paired pulse2*pulse1; run; /*PAIRED TTEST FOR EACH LEVEL OF RAN*/ proc sort data=pulse; by ran; run; proc ttest data=pulse; paired pulse2*pulse1; by ran; run; /*MCNEMAR'S TEST FOR PAIRED CATEGORICAL DATA*/ data newpulse; set pulse; if pulse1 > 80 then hipulse1 = 1; if pulse1 > 0 and pulse1 <=89 then hipulse1=0; if pulse2 > 80 then hipulse2 = 1; if pulse2 > 0 and pulse2 <=89 then hipulse2=0; run; proc freq data=newpulse; tables hipulse1 hipulse2; run; proc freq data=newpulse; tables hipulse1*hipulse2/ agree; run;