Original Program from program editor.

**********************************************;
*** t-tests done with SAS Proc Univariate ***;
**********************************************;

OPTIONS LS=99 PS=256 nocenter nonumber nodate;
   TITLE1 'One sample t-tests';

DATA monkeys; INFILE CARDS MISSOVER;
   TITLE2 'Analysis of Blood Pressure change in Rhesus Monkies';
   INPUT BPChange;
CARDS; RUN;
 0
 4
-3
 2
 0
 1
-4
 5
-1
 4
;
PROC PRINT DATA=monkeys; 
   TITLE3 'Raw data listing';
RUN;

PROC UNIVARIATE DATA=monkeys PLOT; VAR BPChange;
    TITLE3 'Proc Univariate on Blood Pressure Change'; 
RUN;
PROC ttest DATA=monkeys; VAR BPChange;
    TITLE3 'Proc TTEST on Blood Pressure Change'; 
RUN;


****************************************************************;
*** A shipment of apples are supposed to have a diameter of  ***;
*** at least 2.5 inches.  Sample 12 apples and test the      ***;
*** hypothesis that the mean size is equal 2.5 inches.       ***;
*** Reject the shipment if LESS THAN 2.5 inches.             ***;
****************************************************************;

OPTIONS LS=99 PS=256 nocenter nonumber nodate;
   TITLE1 'One sample t-tests';
   TITLE2 'Test the diameter of apples against 2.5 inches';

data apples; infile cards missover;
  LABEL diam = 'Diameter of the apple';
  input diam; diff = diam - 2.5;
cards; run;
2.9
2.1
2.4
2.8
3.1
2.8
2.7
3.0
2.4
3.2
2.3
3.4
;
proc print data=apples; var diam diff; 
   TITLE3 'Raw data listing';
run;

proc univariate data=apples plot; var diam; 
   TITLE3 'Proc Univariate on Apple size'; 
run;
proc univariate data=apples plot; var diff; 
   TITLE3 'Proc Univariate on Apple size difference'; 
run;
proc ttest data=apples H0=2.5; var diam; 
   TITLE3 'Proc TTEST on Apple size'; 
run;


*********************************************************************;
*** Test for differences in seed production at two levels on a    ***;
*** plant (top and bottom).  We have ten vigorous plants bearing  ***;
*** lucerne flowers.  We want to test for differences in the      ***;
*** number of seeds for the average of two pods in each position. ***;
*********************************************************************;

OPTIONS LS=99 PS=256 nocenter nonumber nodate;
   TITLE1 'One sample t-tests';
   TITLE2 'Test comparing seed production for lucerne flowers';

data flowers; infile cards missover;
   TITLE3 'Seed production for top and bottom flowers';
     LABEL top = 'Flowers from the top of the plant';
     LABEL bottom = 'Flowers from the bottom of the plant';
     LABEL diff = 'Difference between top and bottom';
  input top bottom;
    diff = top - bottom;
cards; run;
4.0      4.4
5.2      3.7
5.7      4.7
4.2      2.8
4.8      4.2
3.9      4.3
4.1      3.5
3.0      3.7
4.6      3.1
6.8      1.9
;
proc print data=flowers; var top bottom diff; 
   TITLE4'Raw data listing';
run;

proc univariate data=flowers plot; var diff; 
   TITLE4'Proc Univariate on difference between top and bottom'; 
run;
proc ttest data=flowers; paired top*bottom; 
   TITLE4'Proc Univariate on difference between top and bottom'; 
run;



Below is output from the SAS log (bold) and output from the SAS Output window.



1          **********************************************;
2          *** t-tests done with SAS Proc Univariate ***;
3          **********************************************;
4    
5          OPTIONS LS=99 PS=256 nocenter nonumber nodate;
6             TITLE1 'One sample t-tests';
7    
8          DATA monkeys; INFILE CARDS MISSOVER;
9             TITLE2 'Analysis of Blood Pressure change in Rhesus Monkies';
10            INPUT BPChange;
11         CARDS;

NOTE: The data set WORK.MONKEYS has 10 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds
11       !        RUN;
22         ;
23         PROC PRINT DATA=monkeys;
24            TITLE3 'Raw data listing';
25         RUN;
NOTE: There were 10 observations read from the data set WORK.MONKEYS.
NOTE: The PROCEDURE PRINT printed page 1.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


One sample t-tests
Analysis of Blood Pressure change in Rhesus Monkies
Raw data listing

Obs    BPChange
  1        0  
  2        4  
  3       -3  
  4        2  
  5        0  
  6        1  
  7       -4  
  8        5  
  9       -1  
 10        4  



26   
27         PROC UNIVARIATE DATA=monkeys PLOT; VAR BPChange;
28             TITLE3 'Proc Univariate on Blood Pressure Change';
29         RUN;
NOTE: The PROCEDURE UNIVARIATE printed page 2.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.07 seconds
      cpu time            0.01 seconds



One sample t-tests
Analysis of Blood Pressure change in Rhesus Monkies
Proc Univariate on Blood Pressure Change

The UNIVARIATE Procedure
Variable:  BPChange

Moments
N                          10    Sum Weights                 10
Mean                      0.8    Sum Observations             8
Std Deviation      3.01109061    Variance            9.06666667
Skewness            -0.157506    Kurtosis            -0.9577747
Uncorrected SS             88    Corrected SS              81.6
Coeff Variation    376.386326    Std Error Mean      0.95219046

Basic Statistical Measures
    Location                    Variability

Mean     0.800000     Std Deviation            3.01109
Median   0.500000     Variance                 9.06667
Mode     0.000000     Range                    9.00000
                      Interquartile Range      5.00000

NOTE: The mode displayed is the smallest of 2 modes with a count of 2.

Tests for Location: Mu0=0n
Test           -Statistic-    -----p Value------
Student's t    t  0.840168    Pr > |t|    0.4226
Sign           M         1    Pr >= |M|   0.7266
Signed Rank    S       6.5    Pr >= |S|   0.3984

Quantiles (Definition 5)

Quantile      Estimate
100% Max           5.0
99%                5.0
95%                5.0
90%                4.5
75% Q3             4.0
50% Median         0.5
25% Q1            -1.0
10%               -3.5
5%                -4.0
1%                -4.0
0% Min            -4.0

 Extreme Observations
----Lowest----        ----Highest---
Value      Obs        Value      Obs
   -4        7            1        6
   -3        3            2        4
   -1        9            4        2
    0        5            4       10
    0        1            5        8

   Stem Leaf  Boxplot
      4 000                      3  +-----+
      2 0                        1  |     |
      0 000                      3  *--+--*
     -0 0                        1  +-----+
     -2 0                        1     |
     -4 0                        1     |
        ----+----+----+----+

        Normal Probability Plot
       5+                                *  *++++*++
        |                             *++++++
        |                     * +*+*++
        |                ++*++++
        |          *++++*
      -5+   +++++++
         +----+----+----+----+----+----+----+----+----+----+
             -2        -1         0        +1        +2




30         PROC ttest DATA=monkeys; VAR BPChange;
31             TITLE3 'Proc TTEST on Blood Pressure Change';
32         RUN;
NOTE: There were 10 observations read from the data set WORK.MONKEYS.
NOTE: The PROCEDURE TTEST printed page 3.
NOTE: PROCEDURE TTEST used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds



One sample t-tests
Analysis of Blood Pressure change in Rhesus Monkies
Proc TTEST on Blood Pressure Change

The TTEST Procedure

Statistics
                 Lower CL          Upper CL  Lower CL           Upper CL
Variable      N      Mean    Mean      Mean   Std Dev  Std Dev   Std Dev  Std Err  Minimum  Maximum
BPChange     10    -1.354     0.8     2.954    2.0711   3.0111    5.4971   0.9522       -4        5

T-Tests
Variable      DF    t Value    Pr > |t|
BPChange       9       0.84      0.4226



34   
35         ****************************************************************;
36         *** A shipment of apples are supposed to have a diameter of  ***;
37         *** at least 2.5 inches.  Sample 12 apples and test the      ***;
38         *** hypothesis that the mean size is equal 2.5 inches.       ***;
39         *** Reject the shipment if LESS THAN 2.5 inches.             ***;
40         ****************************************************************;
41   
42         OPTIONS LS=99 PS=256 nocenter nonumber nodate;
43            TITLE1 'One sample t-tests';
44            TITLE2 'Test the diameter of apples against 2.5 inches';
45   
46         data apples; infile cards missover;
47           LABEL diam = 'Diameter of the apple';
48           input diam; diff = diam - 2.5;
49         cards;

NOTE: The data set WORK.APPLES has 12 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
49       !        run;
62         ;
63         proc print data=apples; var diam diff;
64            TITLE3 'Raw data listing';
65         run;
NOTE: There were 12 observations read from the data set WORK.APPLES.
NOTE: The PROCEDURE PRINT printed page 4.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



One sample t-tests
Test the diameter of apples against 2.5 inches
Raw data listing

Obs    diam    diff

  1     2.9     0.4
  2     2.1    -0.4
  3     2.4    -0.1
  4     2.8     0.3
  5     3.1     0.6
  6     2.8     0.3
  7     2.7     0.2
  8     3.0     0.5
  9     2.4    -0.1
 10     3.2     0.7
 11     2.3    -0.2
 12     3.4     0.9





66   
67         proc univariate data=apples plot; var diam;
68            TITLE3 'Proc Univariate on Apple size';
69         run;

NOTE: The PROCEDURE UNIVARIATE printed page 5.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds




One sample t-tests
Test the diameter of apples against 2.5 inches
Proc Univariate on Apple size

The UNIVARIATE Procedure
Variable:  diam  (Diameter of the apple)

Moments
N                          12    Sum Weights                 12
Mean               2.75833333    Sum Observations          33.1
Std Deviation      0.39418116    Variance            0.15537879
Skewness           -0.1184219    Kurtosis            -0.8352969
Uncorrected SS          93.01    Corrected SS        1.70916667
Coeff Variation    14.2905557    Std Error Mean       0.1137903

Basic Statistical Measures
    Location                    Variability
Mean     2.758333     Std Deviation            0.39418
Median   2.800000     Variance                 0.15538
Mode     2.400000     Range                    1.30000
                      Interquartile Range      0.65000

NOTE: The mode displayed is the smallest of 2 modes with a count of 2.

Tests for Location: Mu0=0n
Test           -Statistic-    -----p Value------
Student's t    t   24.2405    Pr > |t|    <.0001
Sign           M         6    Pr >= |M|   0.0005
Signed Rank    S        39    Pr >= |S|   0.0005

Quantiles (Definition 5)

Quantile      Estimate
100% Max          3.40
99%               3.40
95%               3.40
90%               3.20
75% Q3            3.05
50% Median        2.80
25% Q1            2.40
10%               2.30
5%                2.10
1%                2.10
0% Min            2.10

Extreme Observations
----Lowest----        ----Highest---

Value      Obs        Value      Obs
  2.1        2          2.9        1
  2.3       11          3.0        8
  2.4        9          3.1        5
  2.4        3          3.2       10
  2.7        7          3.4       12

   Stem Leaf  Boxplot
     34 0                        1     |
     32 0                        1     |
     30 00                       2  +-----+
     28 000                      3  *-----*
     26 0                        1  |  +  |
     24 00                       2  +-----+
     22 0                        1     |
     20 0                        1     |
        ----+----+----+----+
    Multiply Stem.Leaf by 10**-1

Normal Probability Plot
     3.5+                                         *+++++
        |                                    *+++++
        |                              * +*+++
        |                        * *+*+++
        |                     +*++++
        |                +*++*
        |           +++*+
     2.1+      +++*+
         +----+----+----+----+----+----+----+----+----+----+
             -2        -1         0        +1        +2






70         proc univariate data=apples plot; var diff;
71            TITLE3 'Proc Univariate on Apple size difference';
72         run;
NOTE: The PROCEDURE UNIVARIATE printed page 6.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds





One sample t-tests
Test the diameter of apples against 2.5 inches
Proc Univariate on Apple size difference

The UNIVARIATE Procedure
Variable:  diff

Moments
N                          12    Sum Weights                 12
Mean               0.25833333    Sum Observations           3.1
Std Deviation      0.39418116    Variance            0.15537879
Skewness           -0.1184219    Kurtosis            -0.8352969
Uncorrected SS           2.51    Corrected SS        1.70916667
Coeff Variation    152.586256    Std Error Mean       0.1137903

Basic Statistical Measures
    Location                    Variability

Mean      0.25833     Std Deviation            0.39418
Median    0.30000     Variance                 0.15538
Mode     -0.10000     Range                    1.30000
                      Interquartile Range      0.65000

NOTE: The mode displayed is the smallest of 2 modes with a count of 2.

Tests for Location: Mu0=0n
Test           -Statistic-    -----p Value------

Student's t    t  2.270258    Pr > |t|    0.0443
Sign           M         2    Pr >= |M|   0.3877
Signed Rank    S        25    Pr >= |S|   0.0493

Quantiles (Definition 5)

Quantile      Estimate

100% Max          0.90
99%               0.90
95%               0.90
90%               0.70
75% Q3            0.55
50% Median        0.30
25% Q1           -0.10
10%              -0.20
5%               -0.40
1%               -0.40
0% Min           -0.40

Extreme Observations
----Lowest----        ----Highest---

Value      Obs        Value      Obs

 -0.4        2          0.4        1
 -0.2       11          0.5        8
 -0.1        9          0.6        5
 -0.1        3          0.7       10
  0.2        7          0.9       12

   Stem Leaf  Boxplot
      8 0                        1     |
      6 00                       2     |
      4 00                       2  +-----+
      2 000                      3  *--+--*
      0                             |     |
     -0 00                       2  +-----+
     -2 0                        1     |
     -4 0                        1     |
        ----+----+----+----+
    Multiply Stem.Leaf by 10**-1

Normal Probability Plot
     0.9+                                       ++*++
        |                                 *++*++
        |                            *+*+++
        |                      * *++++
        |                   +++++
        |              *++*+
        |         *++++
    -0.5+    +++++
         +----+----+----+----+----+----+----+----+----+----+
             -2        -1         0        +1        +2





73         proc ttest data=apples H0=2.5; var diam;
74            TITLE3 'Proc TTEST on Apple size';
75         run;
NOTE: There were 12 observations read from the data set WORK.APPLES.
NOTE: The PROCEDURE TTEST printed page 7.
NOTE: PROCEDURE TTEST used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



One sample t-tests
Test the diameter of apples against 2.5 inches
Proc TTEST on Apple size

The TTEST Procedure

Statistics
                 Lower CL          Upper CL  Lower CL           Upper CL
Variable      N      Mean    Mean      Mean   Std Dev  Std Dev   Std Dev  Std Err  Minimum  Maximum
diam         12    2.5079  2.7583    3.0088    0.2792   0.3942    0.6693   0.1138      2.1      3.4

T-Tests
Variable      DF    t Value    Pr > |t|
diam          11       2.27      0.0443




77   
78         *********************************************************************;
79         *** Test for differences in seed production at two levels on a    ***;
80         *** plant (top and bottom).  We have ten vigorous plants bearing  ***;
81         *** lucerne flowers.  We want to test for differences in the      ***;
82         *** number of seeds for the average of two pods in each position. ***;
83         *********************************************************************;
84   
85         OPTIONS LS=99 PS=256 nocenter nonumber nodate;
86            TITLE1 'One sample t-tests';
87            TITLE2 'Test comparing seed production for lucerne flowers';
88   
89         data flowers; infile cards missover;
90            TITLE3 'Seed production for top and bottom flowers';
91              LABEL top = 'Flowers from the top of the plant';
92              LABEL bottom = 'Flowers from the bottom of the plant';
93              LABEL diff = 'Difference between top and bottom';
94           input top bottom;
95             diff = top - bottom;
96         cards;
NOTE: The data set WORK.FLOWERS has 10 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
96       !        run;
107        ;
108        proc print data=flowers; var top bottom diff;
109           TITLE4'Raw data listing';
110        run;
NOTE: There were 10 observations read from the data set WORK.FLOWERS.
NOTE: The PROCEDURE PRINT printed page 8.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds



One sample t-tests
Test comparing seed production for lucerne flowers
Seed production for top and bottom flowers
Raw data listing

Obs    top    bottom    diff
  1    4.0      4.4     -0.4
  2    5.2      3.7      1.5
  3    5.7      4.7      1.0
  4    4.2      2.8      1.4
  5    4.8      4.2      0.6
  6    3.9      4.3     -0.4
  7    4.1      3.5      0.6
  8    3.0      3.7     -0.7
  9    4.6      3.1      1.5
 10    6.8      1.9      4.9



111  
112        proc univariate data=flowers plot; var diff;
113           TITLE4'Proc Univariate on difference between top and bottom';
114        run;
NOTE: The PROCEDURE UNIVARIATE printed page 9.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds



One sample t-tests
Test comparing seed production for lucerne flowers
Seed production for top and bottom flowers
Proc Univariate on difference between top and bottom

The UNIVARIATE Procedure
Variable:  diff  (Difference between top and bottom)

Moments
N                          10    Sum Weights                 10
Mean                        1    Sum Observations            10
Std Deviation      1.59861051    Variance            2.55555556
Skewness           1.66938453    Kurtosis            3.93459317
Uncorrected SS             33    Corrected SS                23
Coeff Variation    159.861051    Std Error Mean      0.50552503

Basic Statistical Measures
    Location                    Variability
Mean     1.000000     Std Deviation            1.59861
Median   0.800000     Variance                 2.55556
Mode     0.600000     Range                    5.60000
                      Interquartile Range      1.90000

Tests for Location: Mu0=0n
Test           -Statistic-    -----p Value------
Student's t    t  1.978141    Pr > |t|    0.0793
Sign           M         2    Pr >= |M|   0.3438
Signed Rank    S      19.5    Pr >= |S|   0.0469

Quantiles (Definition 5)

Quantile      Estimate
100% Max          4.90
99%               4.90
95%               4.90
90%               3.20
75% Q3            1.50
50% Median        0.80
25% Q1           -0.40
10%              -0.55
5%               -0.70
1%               -0.70
0% Min           -0.70

Extreme Observations
----Lowest----        ----Highest---

Value      Obs        Value      Obs
 -0.7        8          1.0        3
 -0.4        1          1.4        4
 -0.4        6          1.5        9
  0.6        7          1.5        2
  0.6        5          4.9       10

   Stem Leaf  Boxplot
      4 9                        1     0
      3
      2
      1 0455                     4  +--+--+
      0 66                       2  *-----*
     -0 744                      3  +-----+
        ----+----+----+----+

Normal Probability Plot
     4.5+                                        *   +++++++
        |                                      ++++++
        |                                ++++++
        |                         +*++*++*  *
        |                   ++*++*
    -0.5+          *  ++*++*
         +----+----+----+----+----+----+----+----+----+----+
             -2        -1         0        +1        +2




115        proc ttest data=flowers; paired top*bottom;
116           TITLE4'Proc Univariate on difference between top and bottom';
117        run;
NOTE: There were 10 observations read from the data set WORK.FLOWERS.
NOTE: The PROCEDURE TTEST printed page 10.
NOTE: PROCEDURE TTEST used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
118  
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           7.03 seconds
      cpu time            0.48 seconds


One sample t-tests
Test comparing seed production for lucerne flowers
Seed production for top and bottom flowers
Proc Univariate on difference between top and bottom

The TTEST Procedure

Statistics
                          Lower CL            Upper CL   Lower CL             Upper CL
Difference            N       Mean     Mean       Mean    Std Dev   Std Dev    Std Dev   Std Err
top - bottom         10     -0.144        1     2.1436     1.0996    1.5986     2.9184    0.5055  

T-Tests
Difference           DF    t Value    Pr > |t|
top - bottom          9       1.98      0.0793



Last modified
by James P. Geaghan
on Wednesday, August 13, 2003