Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS T test


May 27, 2021 SAS


Table of contents


T-tests are performed to calculate the confidence limits of one sample or two independent samples by comparing their average and average differences. T he SAS procedure, called PROC TTEST, is used to perform t tests on a single variable and a pair of variables.

Syntactic

The basic syntax for applying PROC TTEST in SAS is:

PROC TTEST DATA = dataset;
VAR variable;
CLASS Variable;
PAIRED Variable_1 * Variable_2;

The following is a description of the parameters used:

  • Dataset is the name of the dataset.
  • Variable_1 and Variable_2 the variable names of the datasets used in test.

Cases

Below we see a sample t-test, where a variable horsepower estimate with a 95% confidence limit is found.

PROC SQL;
create table CARS1 as
SELECT make,type,invoice,horsepower,length,weight
 FROM 
SASHELP.CARS
WHERE make in ('Audi','BMW')
;
RUN;

proc ttest data=cars1 alpha=0.05 h0=0;
 	var horsepower;
   run;

When we execute the code above, we get the following results:

SAS T test

Pairing t-test

Pair the T test to test whether the two depending variables are statistically different from each other.

Cases

Since the length and weight of the car will depend on each other, we apply the pairing T test as shown below.

proc ttest data=cars1 ;
    paired weight*length;
   run;

When we execute the code above, we get the following results:

SAS T test

Two samples t-test

This t-test is designed to compare the averages of the same variables between two sets.

Cases

In our example, we compared the average variable horsepower between two different models ("Audi" and "BMW").

proc ttest data=cars1 sides=2 alpha=0.05 h0=0;
 	title "Two sample t-test example";
 	class make; 
	var horsepower;
   run;
  

When we execute the code above, we get the following results:

SAS T test