11.6 - The UNIVARIATE procedure11.6 - The UNIVARIATE procedure
In this section, we take a brief look at the UNIVARIATE procedure just so we can see how its output differs from that of the MEANS and SUMMARY procedures.
The following UNIVARIATE procedure illustrates the (almost) simplest version of the procedure, in which it tells SAS to perform a univariate analysis on the red blood cell count (rbc) variable in the icdb.hem2 data set:
PROC UNIVARIATE data = icdb.hem2; title 'Univariate Analysis of RBC'; var rbc; RUN;
The simplest version of the UNIVARIATE procedure would be one in which no VAR statement is present. Then, SAS would perform a univariate analysis for each numeric variable in the data set. The DATA= option merely tells SAS on which data set you want to do a univariate analysis. As always, if the DATA= option is absent, SAS performs the analysis on the current data set. The VAR statement tells SAS to perform a univariate analysis on the variable rbc.
Launch and run the program and review the output to familiarize yourself with the kinds of summary statistics the univariate procedure calculates. You should see five major sections in the output with the following headings: Moments, Basic Statistical Measures, Tests for Location Mu0 = 0, Quantiles, and Extreme Observations. Here's what the first three sections of the output look like:
Univariate Analysis of RBC
The UNIVARIATE Procedure
|Uncorrected SS||12588.5073||Corrected SS||98.505075|
|Coeff Variation||8.88771825||Std Error Mean||0.0156422|
and the fourth section:
Quantiles (Definition 5)
and the fifth and final section:
With an introductory statistics course in your background, the output should be mostly self-explanatory. For example, the output tells us that the average ("Mean") red blood cell count of the 635 subjects ("N") in the data set is 4.435 with a standard deviation of 0.394. The median ("50% Median") red blood cell count is 4.41. The smallest red blood cell count in the data set is 3.12 (observation #218), while the largest is 5.95 (observation #465).
When you specify the NORMAL option, SAS will compute four different test statistics for the null hypothesis that the values of the variable specified in the VAR statement are a random sample from a normal distribution. The four test statistics calculated and presented in the output are: Shapiro-Wilk, Kolmogorov-Smirnov, Cramer-von Mises, and Anderson-Darling.
When you specify the PLOT option, SAS will produce a histogram, a box plot, and a normal probability plot for each variable specified in the VAR statement. (Note that in SAS 9.4, you need to disable "ODS Graphics" to get the plots in the listing output. To do so, go to menu Tools> Options > Preferences, and uncheck the box Use ODS Graphics under the tab Results. Click OK.)
If you have a BY statement specified as well, SAS will produce each of these plots for each level of the BY statement.
The following UNIVARIATE procedure illustrates the NORMAL and PLOT options on the variable rbc of the hematology data set:
PROC UNIVARIATE data = icdb.hem2 NORMAL PLOT; title 'Univariate Analysis of RBC with NORMAL and PLOT Options'; var rbc; RUN;
Launch and run the SAS program. Review the output to familiarize yourself with the change in the UNIVARIATE output that arises from the NORMAL and PLOT options. You should see a new section called Tests for Normality that contains the four "test for normality" test statistics and corresponding P-values:
Tests for Normality
|Sharpiro-Wilk||W||0.992948||Pr < W||0.0044|
|Kolmogorov-Smirnov||D||0.033851||Pr > D||0.0771|
|Cramer-von Mises||W-Sq||0.145326||Pr > W-Sq||0.0279|
|Anderson-Darling||A-Sq||1.070646||Pr > A-Sq||0.0085|
At the end of the output, you should see the histogram and box plot:
as well as the normal probability plot for the rbc variable:
When you use the UNIVARIATE procedure's ID statement, SAS uses the values of the variable specified in the ID statement to indicate the five largest and five smallest observations rather than the (usually meaningless) observation number. The following UNIVARIATE procedure uses the subject number (subj) to indicate extreme values of red blood cell count (rbc):
PROC UNIVARIATE data = icdb.hem2; title 'Univariate Analysis of RBC with ID Option'; var rbc; id subj; RUN;
Launch and run the SAS program. Review the output to familiarize yourself with the change in the UNIVARIATE output that arises from using the ID statement. In Example 11.14, the UNIVARIATE output indicated that observation #218 has the smallest red blood cell count in the data set (3.12), while observation #465 has the largest (5.95). Now, because of the use of the subject number as an ID variable ("id subj"):
SAS reports the more helpful information that subject 220007 has the smallest red blood cell count, while subject 420074 has the largest.
You shouldn't be surprised to learn that the UNIVARIATE procedure can do much more than what we can address now. Just as the BY statement can be used in the MEANS and SUMMARY procedures to categorize the observations in the input data set into subgroups, so can a BY statement be used in the UNIVARIATE procedure. And, just as an OUTPUT statement can be used in the MEANS and SUMMARY procedures to create summarized data sets, so can an OUTPUT statement be used in the UNIVARIATE procedure. For more information about the functionality and syntax of the UNIVARIATE procedure, see the SAS Help and Documentation.