Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 37 ยท Statistics and Reporting

PROC UNIVARIATE and PROC TTEST

Describe distributions with PROC UNIVARIATE (moments, quantiles, normality tests, histograms) and compare means with PROC TTEST (one-sample, two-sample, paired), with Python stand-ins.

Chapter 8 moves from preparing data to analyzing it. Two procedures cover the first questions every analysis asks: what does the distribution of this variable look like? (PROC UNIVARIATE) and do two groups differ in their means? (PROC TTEST).

SAS cannot run on this site. sas blocks are read-only, and I show no real SAS listings. The Python TryIts (standard library only) compute the same statistics, so you can check what the SAS output means. Real SAS reports many more lines than the stand-ins print.

PROC UNIVARIATE

SAS
proc univariate data=work.patients;
  var weight;
run;

For each variable listed in var, the output has several tables:

  • Moments: N, mean, standard deviation, skewness, kurtosis, sum, variance, coefficient of variation.
  • Basic statistical measures: location (mean, median, mode) and variability (std deviation, variance, range, interquartile range).
  • Tests for location: tests of the hypothesis that the mean equals 0 (a Student's t test, a sign test, a signed-rank test). Change the target with mu0=70.
  • Quantiles: 100% Max, 99%, 95%, 90%, 75% Q3, 50% Median, 25% Q1, 10%, 5%, 1%, 0% Min.
  • Extreme observations: the five lowest and highest values with their observation numbers, a fast outlier check.
  • Missing values: how many were skipped.

Statements and options that make it useful:

SAS
proc univariate data=work.patients normal plot;
  class sex;                      /* separate results per group */
  var weight;
  histogram weight / normal;      /* histogram with a fitted normal curve */
  qqplot weight / normal(mu=est sigma=est);
  output out=work.wstats mean=m std=s pctlpts=5 95 pctlpre=p;
run;
  • normal adds tests of normality (Shapiro-Wilk, Kolmogorov-Smirnov and others). A small p-value says the data look unlike a normal distribution; in large samples these tests flag tiny departures, so always look at the qqplot too.
  • plot draws old-style text plots (stem-and-leaf, box plot, normal probability plot); histogram and qqplot statements draw proper graphics with ODS Graphics.
  • output out= saves chosen statistics, including arbitrary percentiles with pctlpts and pctlpre.
  • freq, weight, by, and id statements work as in other procedures. id labels the extreme observations with a variable such as a patient number.

Stand-in: what the moments and quantiles mean

Python Stand-in: moments, quantiles and the IQR rule

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The value 120 pulls the mean above the median and gives a strongly positive skewness. That mean-above-median pattern is the first thing to look for in the UNIVARIATE output, and the 1.5-times-IQR rule is how box plots decide which points to draw as outliers.

PROC TTEST

PROC TTEST compares means. Its three common uses:

SAS
/* 1. One sample: is the mean equal to a reference value? */
proc ttest data=work.patients h0=70;
  var weight;
run;

/* 2. Two independent groups */
proc ttest data=work.patients;
  class sex;                      /* exactly two levels */
  var weight;
run;

/* 3. Paired measurements (before and after) */
proc ttest data=work.trial;
  paired after * before;
run;

For the two-sample test, SAS prints both versions of the test:

  • Pooled (assumes equal variances), and
  • Satterthwaite (does not assume equal variances).

A third table, Equality of Variances (a folded F test), tells you which row to read: when it is not significant, the pooled test is reasonable, but many analysts always report Satterthwaite because it works in both cases. The output also gives confidence intervals for each group mean and for the difference. With plots=summary SAS draws histograms and box plots for each group.

Test results come with assumptions: independent observations, roughly normal data (or a reasonably large sample), and for the pooled version equal variances. When the distribution is clearly skewed, use proc npar1way wilcoxon instead.

Stand-in: a two-sample t statistic

The stand-in computes the Satterthwaite (Welch) t statistic and its two-sided p-value by integrating the t density numerically, so it needs no extra libraries.

Python Stand-in: Welch two-sample t test

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The group means differ by a few units, the t statistic is large relative to its standard error, and the p-value is small. The same three numbers (t Value, DF, Pr > |t|) appear in the SAS table for the Satterthwaite method. A small p-value says the difference is unlikely under "no difference", not that it is large or important, so read the confidence interval for the size of the effect.

Stand-in: a paired test is a one-sample test

A paired t test is a one-sample test on the differences. This is why paired after * before; needs the two measurements in the same row.

Python Stand-in: paired t statistic

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Every participant improved by a small, consistent amount, so the standard deviation of the differences is small and the t statistic is large. A two-sample test on the same numbers would hide that consistency, because it treats the two columns as unrelated groups.

Reading the results responsibly

  1. Check the data first: counts, extremes, missing values (UNIVARIATE, FREQ).
  2. Look at the shape before trusting a test that assumes normality.
  3. Report the estimate and its confidence interval, not just p.
  4. Decide your test (one- or two-sided, paired or not) before looking at results.
  5. Never run many tests and report only the significant one; adjust for multiple comparisons.

Correlation and regression, the next set of tools, follow in PROC CORR and PROC REG.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which PROC UNIVARIATE option requests tests of normality?

    The NORMAL option adds Shapiro-Wilk, Kolmogorov-Smirnov and related tests.
  2. 2. In PROC TTEST with a CLASS statement, what does the Satterthwaite row assume?

    Satterthwaite is the unequal-variance version; the pooled row assumes equal variances.
  3. 3. A paired t test is equivalent to what?

    Pairing removes between-subject variation by testing whether the mean of the differences is zero.
  4. 4. A distribution has mean 80 and median 71. What does that suggest?

    A mean well above the median points to a long right tail or high outliers.

Summary

  • PROC UNIVARIATE reports moments, quantiles, extremes and tests, with histogram, qqplot and normal for shape.
  • PROC TTEST handles one-sample (h0=), two-sample (class) and paired (paired a * b) comparisons.
  • The two-sample output has pooled and Satterthwaite rows plus a variance test.
  • A p-value does not measure effect size; read the confidence interval.
  • Look at the distribution before relying on any test that assumes normality.

Next: PROC CORR and PROC REG