Chapter 1 Statistics With SAS

Week 1

One-sample T Test

/* This SAS program conducts a one-sample t-test to test whether 
the mean sale price of houses in the STAT1.ameshousing3 dataset is equal to $135,000. */

/* The following line enables the use of ODS graphics, 
which allows SAS to generate graphical output. */

ods graphics;

proc ttest data=STAT1.ameshousing3 
    plots(shownull)=interval  
/* This line specifies that the confidence interval should be plotted. 
The "shownull" option specifies that the null hypothesis value (in this case, 
$135,000) should be shown on the plot. */
    H0=135000;  
/* This line specifies the null hypothesis value for the mean sale price. */
    var SalePrice;  
/* This line specifies that the variable SalePrice should be used for the t-test. */
    title "One-Sample t-test testing whether mean SalePrice=$135,000";  
/* This line adds a title to the output, describing the t-test being conducted. */
run;

/* This line clears the title that was added to the output. */
title;

Example 2:

/st101s01.sas/ /Part A/
/* This is a SAS program that analyzes the distribution of 
two interval variables (BodyTemp and HeartRate) using a 
histogram with normal and kernel density plots. */

/* Define a macro variable named interval that contains 
the names of the interval variables. */
%let interval=BodyTemp HeartRate;

/* Turn on ODS graphics for generating graphical output, 
and specify that only histograms will be displayed. */
ods graphics;
ods select histogram;

/* Use PROC UNIVARIATE to generate a histogram with 
normal and kernel density plots for the interval variables. */
proc univariate data=STAT1.NormTemp noprint;
    var &interval; 
/* Analyze the interval variables specified in the macro variable interval. */
    histogram &interval / normal kernel; 
/* Generate a histogram with normal and kernel density plots for the interval variables. */
    inset n mean std / position=ne; 
/* Include the sample size, mean, and standard deviation in the upper right corner of the graph. */
    title "Interval Variable Distribution Analysis"; 
/* Specify a title for the graph. */
run;

/* Reset the title to blank. */
title;

/st101s01.sas/ /Part B/
/* This part of the SAS program tests whether the mean body 
temperature is significantly different from the conventional value of 98.6°F. */

/* Use PROC TTEST to perform a one-sample t-test for the BodyTemp variable. /
proc ttest data=STAT1.NormTemp h0=98.6
           plots(only shownull)=interval;
    var BodyTemp; / Analyze the BodyTemp variable. /
    title 'Testing Whether the Mean Body Temperature = 98.6'; / Specify a title for the output. */
run;

/* Reset the title to blank. */
title;

Two-samples T Test

/* st101d03.sas */

/* This is a SAS program that performs a two-sample t-test to 
compare the mean sale prices of houses with and without masonry veneer. */

/* Turn on ODS graphics for generating graphical output. */
ods graphics;

/* Use PROC TTEST to perform the two-sample t-test. */
proc ttest data=STAT1.ameshousing3 plots(shownull)=interval;
/* Specify the dataset to be used and display a confidence interval plot for the null hypothesis value. */
    class Masonry_Veneer; 
/* Define the categorical variable Masonry_Veneer as a CLASS variable. */
    var SalePrice; 
/* Define the variable SalePrice as the continuous variable of interest. */
    format Masonry_Veneer $NoYes.; 
/* Specify the format of the values of the Masonry_Veneer variable as "No" or "Yes". */
    title "Two-Sample t-test Comparing Masonry Veneer, No vs. Yes"; 
/* Specify a title for the output. */
run;

/* Reset the title to blank. */
title;

The code above performs a two-sample t-test to compare the mean sale prices of houses with and without masonry veneer. The plots(shownull)=interval option displays a confidence interval plot for the null hypothesis value. The class statement specifies the categorical variable Masonry_Veneer as a CLASS variable. The var statement specifies “SalePrice” as the continuous variable of interest. The format statement specifies that the values of “Masonry_Veneer” are either “No” or “Yes”. The title statement adds a title to the output. The “run” statement executes the PROC TTEST procedure. The final title statement resets the title to blank.