Lesson 11: Summarizing Continuous DataLesson 11: Summarizing Continuous Data
As you now know, in addition to creating pretty reports, the REPORT procedure can be used to calculate some basic descriptive statistics. There are a number of procedures that are available in SAS, however, that are designed specifically to produce a variety of different descriptive statistics and to display them in meaningful reports. The four procedures in particular, of which I am thinking, are the MEANS, SUMMARY, UNIVARIATE, and FREQ procedures.
The FREQ procedure is used to summarize discrete data values, and therefore can be used to calculate summary statistics such as the percentage of people with blue eyes and the number of elm trees succumbing to Dutch elm disease. We'll learn about the FREQ procedure in the next (and final!) lesson.
The MEANS, SUMMARY, and UNIVARIATE procedures are used to summarize continuous numeric values, and therefore can be used to calculate statistics, such as mean height, median salary, and minimum mileage. We'll learn about these three procedures in this (the next to final!) lesson.
We'll work mostly with the MEANS procedure. Then, since the SUMMARY and UNIVARIATE procedures have similar options and statements as the MEANS procedure, we'll spend less time on them. The greatest difference between the three procedures is that the UNIVARIATE procedure calculates a few more additional statistics not available in the MEANS and SUMMARY procedures. If you do not need to calculate the additional statistics that are available in UNIVARIATE, however, it is much more efficient to use the MEANS and SUMMARY procedures.
All three of the procedures take the following generic form:
PROC PROCNAME options; statement1; statement2; etc; RUN;
where, not surprisingly, PROCNAME stands for the name of the procedure, and is therefore — either MEANS, SUMMARY, or UNIVARIATE.
Upon completing this lesson, you should be able to use the three procedures that are available in SAS — MEANS, and SUMMARY, and UNIVARIATE — to perform various basic descriptive statistics on the numeric variables in a data set, including:
- use the VAR statement to tell SAS which numeric variables to analyze
- use the various statistic keywords to tell SAS which summary statistics to calcuate
- use the MAXDEC= and FW= options to tell SAS how to format the report containing the summary statistics
- use the NOPRINT option of the MEANS procedure to suppress printing of the default report
- use the PRINT option of the SUMMARY procedure to generate a report containing the summary statistics
- use the BY statement to tell SAS to perform a separate analysis for each BY-group created by the variables appearing in the BY statement
- use the CLASS statement in the MEANS and SUMMARY procedures to tell SAS to form subgroups before calculating summary statistics
- use the OUTPUT statement to create a data set containing summary statistics rather than the standard printed output
- use the MEANS and PLOT procedures to create a quick-and-dirty interaction plot
- use the NORMAL option of the UNIVARIATE procedure to tell SAS to compute four different "test for normality" statistics
- use the PLOT option of the UNIVARIATE procedure to tell SAS to create a histogram, boxplot, and a normal probability plot
- use the ID statement in the UNIVARIATE procedure to tell SAS to use the values of the variable indicated in the ID statement to indicate the five largest and five smallest observations
11.1 - The MEANS and SUMMARY Procedures11.1 - The MEANS and SUMMARY Procedures
In this section, we'll learn the syntax of the simplest MEANS and SUMMARY procedures, as well as familiarize ourselves with the output they generate.
Throughout our investigation of the MEANS, SUMMARY, and UNIVARIATE procedures, we'll use the hematology data set arising from the ICDB Study. The following program tells SAS to display the contents, and print the first 15 observations, of the data set:
OPTIONS PS = 58 LS = 80 NODATE NONUMBER; LIBNAME icdb 'C:\Simon\Stat480WC\fa08\11means\sasndata'; PROC CONTENTS data = icdb.hem2 position; RUN; PROC PRINT data = icdb.hem2 (OBS = 15); RUN;
First, click the link to save the hematology data set to a convenient location on your computer. Then, launch the SAS program, and edit the LIBNAME statement so that it reflects the location in which you saved the data set. Finally, run the program. You may recall that the CONTENTS procedure's POSITION option tells SAS to display the contents of the data set in the order in which the variables appear in the data set. Therefore, you should see output that looks something like this:
The CONTENS Procedure
Variables in Creation Order
The first two variables, subj and hosp, tell us the subject number and at what hospital the subject's data were collected. The remaining variables, wbc, rbc, hemog, ... are the blood data variables of most interest. For example, the variables wbc and rbc contain the subject's white blood cell and red blood cell counts, respectively. The really important thing to note when reviewing the output is that all of the blood data variables are continuous numeric variables, which lend themselves perfectly to a descriptive analysis using the MEANS procedure.
The MEANS procedure can include many statements and options for specifying the desired statistics. For the sake of simplicity, we'll start out with the most basic form of the MEANS procedure. The following program simply tells SAS to display basic summary statistics for each numeric variable in the icdb.hem2 data set:
PROC MEANS data = icdb.hem2; RUN;
Launch and run the SAS program, and review the output to familiarize yourself with the summary statistics that the MEANS procedure calculates by default. As you can see, in its most basic form, the MEANS procedure prints N (the number of nonmissing values), the mean, the standard deviation, and the minimum and maximum values of every numeric variable in the data set.
In most cases, you probably don't want SAS to calculate summary statistics for every numeric variable in your data set. Instead, you'll probably just want to focus on a few important variables. For our hematology data set, for example, it doesn't make much sense for SAS to calculate summary statistics for the subj and hosp variables. After all, how does it help us to know that the average subj number is 327199.5?
The following program uses the MEANS procedure's VAR statement to restrict SAS to summarizing just the seven blood data variables in the icdb.hem2 data set:
PROC MEANS data = icdb.hem2; var wbc rbc hemog hcrit mcv mch mchc; RUN;
Launch and run the SAS program, and review the output to convince yourself that the subj and hosp variables have been excluded from the analysis.
The other thing you might notice about the output is that there are many more decimal places displayed than are necessary. By default, SAS uses the best. format to display values in reports created by the MEANS procedure. In a technical sense, it means that SAS chooses the format that provides the most information about the summary statistics while maintaining a default field width of 12. In a practical sense, it means that often too many decimal places are displayed.
The following program uses the MEANS procedure's MAXDEC = option to set the maximum number of decimal places displayed to 2, and the FW= option to set the maximum field width printed to 10:
PROC MEANS data = icdb.hem2 MAXDEC = 2 FW = 10; var wbc rbc hemog hcrit mcv mch mchc; RUN;
Launch and run the SAS program, and review the output to convince yourself that the maximum number of decimal places and field widths have been modified as claimed. Let's check out the SUMMARY procedure now.
The following program is identical to the program in the previous example except for two things:
- The MEANS keyword has been replaced with the SUMMARY keyword
- The PRINT option has been added to the PROC statement:
PROC SUMMARY data = icdb.hem2 MAXDEC = 2 FW = 10 PRINT; var wbc rbc hemog hcrit mcv mch mchc; RUN;
The MEANS and SUMMARY procedures perform the same functions except for the default setting of the PRINT option. By default, the MEANS procedure produces printed output, while the SUMMARY procedure does not. With the MEANS procedure, you have to use the NOPRINT option to suppress printing, while with the SUMMARY procedure, you have to use the PRINT option to get a printed report.
Launch and run the SAS program, and review the output to convince yourself that there is no difference between the two reports created by the MEANS and SUMMARY procedures.
Oooops, wait a second here .... if you're not careful, there is actually a difference. The VAR statement in the above program tells SAS which of the (numeric) variables to summarize. If you do not include a VAR statement in the SUMMARY procedure, SAS merely gives a simple count of the number of observations in the data set. To convince yourself of this, delete the VAR statement, and re-run the SAS program. You should see output that looks something like this:
The SUMMARY Procedure
11.2 - Specifying Statistics11.2 - Specifying Statistics
The default statistics that the MEANS procedure produces — N, mean, standard deviation, minimum, and maximum — might not be the ones that you actually need. You might prefer to limit your output to just the mean and standard deviation of the values. Or you might want to compute a completely different statistic, such as the median or range of values.
In order to tell SAS to calculate summary statistics other than those calculated by default, simply place the desired statistics keywords as options in the PROC MEANS statement.
The following program tells SAS to calculate and display the sum, range and median of the red blood cell counts appearing in the icdb.hem2 data set:
PROC MEANS data=icdb.hem2 fw=10 maxdec=2 sum range median; var rbc; RUN;
Launch and run the SAS program, and review the output to convince yourself that the report is generated as described. You might want to note, in particular, that when you specify a statistic in the PROC MEANS statement, the default statistics are not produced. Incidentally, you can generate the exact same report using the SUMMARY procedure, providing you again add the PRINT option to the end of the PROC statement.
The following keywords can be used with the MEANS and SUMMARY procedures to compute statistics:
|CLM||Two-sided confidence limit for the mean|
|CSS||Corrected sum of squares|
|CV||Coefficient of variation|
|LCLM||One-sided confidence limit below the mean|
|N||No. of observations with non-missing values|
|NMISS||No. of observations with missing values|
|STDERR||Standard error of the mean|
|SUMWGT||Sum of the Weight variable values|
|UCLM||One-sided confidence limit above the mean|
|USS||Uncorrected sum of squares|
|MEDIAN or P50||Median or 50th percentile|
|Q1 or P25||Lower quartile or 25th percentile|
|Q3 or P75||Upper quartile or 75th percentile|
|QRANGE||Difference between upper and lower quartiles: Q3-Q1|
|PROBT||Probability of a greater absolute value for the t value|
|T||Student's t for testing that the population mean is 0|
11.3 - Group Processing11.3 - Group Processing
All of the examples we've looked at so far have involved summarizing all of the observations in the data set. In many cases, we'll instead want to tell SAS to calculate summary statistics for certain subgroups. For example, it makes more sense to calculate the average height for males and females separately rather than calculating an average height of all individuals together. In this section, we'll investigate two ways of producing summary statistics for subgroups. One approach involves using a CLASS statement, and the other involves using a BY statement. As you'll soon see, the approach you choose to use will depend most on how you'd like your final report to look.
The following program uses the VAR and CLASS statements to tell SAS to calculate the default summary statistics of the rbc, wbc, and hcrit variables separately for each of the nine hosp values:
PROC MEANS data=icdb.hem2 fw=10 maxdec=2; var rbc wbc hcrit; class hosp; RUN;
First, you should note that the variables appearing in the CLASS statement need not be character variables. Here, we use the numeric variable hosp to break up the 635 observations in the icdb.hem2 data set into nine subgroups. When CLASS variables are numeric, they should of course contain a limited number of discrete values that represent meaningful subgroups. Otherwise, you will be certain to generate an awful lot of useless output.
Now, launch and run the SAS program, and review the output to convince yourself that the report is generated as described. As you can see, the MEANS procedure does not generate statistics for the CLASS variables. Their values are instead used only to categorize the data.
Let's see what happens when our CLASS statement contains more than one variable.
The following program reads some data on national parks into a temporary SAS data set called parks, and then uses the MEANS procedure's VAR and CLASS statements to tell SAS to sum the number of musems and camping facilities for each combination of the Type and Region variables:
DATA parks; input ParkName $ 1-21 Type $ Region $ Museums Camping; DATALINES; Dinosaur NM West 2 6 Ellis Island NM East 1 0 Everglades NP East 5 2 Grand Canyon NP West 5 3 Great Smoky Mountains NP East 3 10 Hawaii Volcanoes NP West 2 2 Lava Beds NM West 1 1 Statue of Liberty NM East 1 0 Theodore Roosevelt NP West 2 2 Yellowstone NP West 9 11 Yosemite NP West 2 13 ; RUN; PROC MEANS data = parks fw = 10 maxdec = 0 sum; var museums camping; class type region; RUN;
Now, launch and run the SAS program, and review the output. You should see that, for example, SAS determined that the number of museums in National Monuments in the East is 2. The number of museums in National Monuments in the West is 3. And so on.
It is probably actually more important here to note how SAS processed the CLASS statement. As you can see, the Type variable appears first and the Region variable appears second in the CLASS statement. For that reason, the Type variable appears first and the Region variable appears second in the output. In general, the order of the variables in the CLASS statement determines their order in the output table. To convince yourself of this, you might want to change the order of the variables as they appear in the CLASS statement, and re-run the SAS program to see what you get.
Like the CLASS statement, the BY statement specifies variables to use for categorizing observations. The following program uses the MEANS procedure's BY statement to categorize the observations in the parks data set into four subgroups, as determined by the Type and Region variables, before calculating the sum, minimum and maximum of the museums and camping values for each of the subgroups:
PROC SORT data = parks out = srtdparks; by type region; RUN; PROC MEANS data = srtdparks fw = 10 maxdec = 0 sum min max; var museums camping; by type region; RUN;
You might want to just go ahead and launch and run the SAS program to see what the report looks like when you use a BY statement instead of a CLASS statement to form the subgroups. You might recall that when you use a CLASS statement, SAS generates a single large table containing all of the summary statistics. As you can see in the output here, when you instead use a BY statement, SAS generates a table for each combination of the Type and Region variables. To be more specific, SAS creates four tables here — one for Type = NM and Region = East, one for Type = NP and Region = East, one for Type = NM and Region = West, and one for Type = NP and Region = West.
Of course, there is one thing we've not addressed so far in this code ... that's the SORT procedure. Unlike CLASS processing, BY-group processing requires that your data be sorted in the order of the variables that appear in the BY statement. If the observations in your data set are not sorted in order by the variables appearing in the BY statement, then you have to use the SORT procedure to sort your data set before using it in the MEANS procedure. Don't forget that if you don't specify an output data set using the OUT= option, then the SORT procedure overwrites your initial data set with the newly sorted observations. Here, our SORT procedure tells SAS to sort the parks data set by the Type and Region variables, and to store the sorted data set in a new data set called srtdparks.
In closing off our discussion of group processing, we should probably discuss which approach — the CLASS statement or the BY statement — is more appropriate. My personal opinion is that it's all a matter of preference. If you prefer to see your summary statistics in one large table, then you should use the CLASS statement. If you instead prefer to see your summary statistics in a bunch of smaller tables, then you should use the BY statement. My personal opinion doesn't take into account the efficiency of your program, however. The advantage of the CLASS statement is that it is easier to use since you need not sort the data first. The advantage of the BY statement is that it can be more efficient when you are categorizing data by many variables.
11.4 - Creating Summarized Data Sets11.4 - Creating Summarized Data Sets
There are many situations, when performing statistical analyses on continuous data, in which you want to create a data set whose observations contain summary statistics rather than observations containing the original raw data. For example, you might want to create a graph that compares the average weight loss of subjects at, say, ten different weight loss clinics. One way of creating such a graph is to first create a data set that contains ten observations — one for each of the clinics — and an average weight loss variable. The MEANS procedure's OUTPUT statement, in conjunction with the NOPRINT option, provides the mechanism to create such a data set rather than the standard printed output.
The NOPRINT option tells SAS to suppress all printed output. The OUTPUT statement, which tells SAS to create the output data set, in general, takes the form:
OUTPUT OUT=dsn keyword1=name1 keyword2=name2 ....;
where dsn is the name of the data set you want to create, and keyword1 is the first statistic you want dumped to the output data set and name1 is the name you want to call the variable in the data set representing that first statistic. Similarly, keyword2 is the second statistic you want dumped to the output data set and name2 is the name you want to call the variable in the data set representing that second statistic. And so on. When you use the OUTPUT statement without specifying any keywords, the default summary statistics N, MEAN, STD, MIN, and MAX are produced for all of the numeric variables or for all of the variables that are listed in the VAR statement.
The following program uses the MEANS procedure's OUTPUT statement (and NOPRINT option) to create a temporary data set called hospsummary that has one observation for each hospital that contains summary statistics for the hospital:
PROC MEANS data=icdb.hem2 NOPRINT; var rbc wbc hcrit; class hosp; output out = hospsummary mean = MeanRBC MeanWBC MeanHCRIT median = MedianRBC MedianWBC MedianHCRIT; RUN; PROC PRINT; title 'Hospital Statistics'; RUN;
Let's first review the code. The VAR statement tells SAS the three variables — rbc, wbc, and hcrit — that we want summarized. The CLASS statement tells SAS that we want to categorize the observations by the value of the hosp variable. The OUT= portion of the OUTPUT statement tells SAS that we want to create a temporary data set called hospsummary. The MEAN= portion of the OUTPUT statement tells SAS to calculate the average of the rbc, wbc, and hcrit values and store the results, respectively, in three new variables called MeanRBC, MeanWBC, and MeanHCRIT. The MEDIAN= portion of the OUTPUT statement tells SAS to calculate the median of the rbc, wbc, and hcrit values and store the results, respectively, in three new variables called MedianRBC, MedianWBC, and MedianHCRIT. Note that, for each keyword, the variables must be listed in the same order as they appear in the VAR statement.
The NOPRINT option of the PROC MEANS statement tells SAS to suppress printing of the summary statistics. We must use the PRINT procedure then to tell SAS to print contents of the hospsummary data set. Because the PROC PRINT statement contains no DATA= option, SAS prints the current data set. The data set created by the MEANS procedure becomes the most recent data set. Therefore, the hospsummary data set is the one that is printed.
Now, launch and run the SAS program and review the output to make sure you understand the summarized data set we created. As we'd expect, the data set contains the hosp variable and the six requested variables, MeanRBC, MeanWBC, ..., MedianHCRIT, that contain the summary statistics. As you can see, the data set also contains two additional variables, _TYPE_ and _FREQ_.
Whenever you use a CLASS statement to create an output data set containing statistics on subgroups, SAS automatically creates these two additional variables. Not surprisingly, the _FREQ_ variable indicates the number of observations contributing to each of the statistics calculated. The _TYPE_ variable indicates what kind of a summary statistic each of the observations in hospsummary contains. You can see that, here, _TYPE_ takes on two possible values 0 and 1. When _TYPE_ = 1, it means that the summary statistic is at the subgroup (hosp) level. That's why you'll see that _TYPE_ = 1 for nine of the observations in hospsummary — one for each hospital. All we really wanted here were these nine observations, but SAS had to complicate matters by giving us this "bonus" observation in which _TYPE_ = 0. When _TYPE_ = 0, it means that the summary statistics are overall summary statistics. That's why for the one observation in which _TYPE_ = 0, you'll see that _FREQ_ = 635. That tells us that all of the observations in icdb.hem2 went into calculating the means and medians for that observation in hospsummary. It should also make sense then that hosp = . for that observation. Ugh, this is sounding messy!
You can also create a summarized data set using the SUMMARY procedure. The following program is identical to the program in the previous example except for two things:
- The MEANS keyword has been replaced with the SUMMARY keyword
- The NOPRINT option has been removed from the PROC statement:
PROC SUMMARY data=icdb.hem2; var rbc wbc hcrit; class hosp; output out = hospsummary mean = MeanRBC MeanWBC MeanHCRIT median = MedianRBC MedianWBC MedianHCRIT; RUN; PROC PRINT; title 'Hospital Statistics'; RUN;
There's nothing really new here. This example should just reinforce the fundamental difference between the SUMMARY and MEANS procedure. The SUMMARY procedure by default does not print output. That's why it is not necessary to use a NOPRINT option to tell SAS to suppress printing of output. This example should also reinforce the fundamental similarity between the SUMMARY and MEANS procedure, namely that the two procedures use identical syntax and produce identical output. Launch and run the SAS program, and review the output to convince yourself that there is no difference between the two data sets created by the MEANS and SUMMARY procedures.
You can also create a summarized data set similar to the hospsummary data set created in the previous two examples by using a BY statement instead of a CLASS statement. The following program does just that:
PROC SORT data = icdb.hem2 out = srtdhem2; by hosp; RUN; PROC MEANS data=srtdhem2 NOPRINT; var rbc wbc hcrit; by hosp; output out = hospsummary mean = MeanRBC MeanWBC MeanHCRIT median = MedianRBC MedianWBC MedianHCRIT; RUN; PROC PRINT; title 'Hospital Statistics'; RUN;
As you can see, the only difference between this program and that in Example 11.10 is that the CLASS statement was replaced by a BY statement, and of course because of that, we had to add a SORT procedure so we could sort the data in icdb.hem2 by hosp. Launch and run the SAS program, and review the output to convince yourself that there is not much of a difference between the resulting hospsummary data set here and that in Examples 11.10 and 11.11.
Well, okay, here _TYPE_ = 0 means that all of the observations here contain summary statistics at the subgroup level. The meaning of _TYPE_ should now seem very confusing to you. Fortunately, we don't need to worry about it much! There is always SAS Help and Documentation available if you're dying to learn more about it. The more important thing to note here is that the MEANS procedure summarizes each BY group as an independent subset of the input data, and therefore, SAS does not produce any sort of overall summarization as it does when using the CLASS statement.
11.5 - Interaction Plots11.5 - Interaction Plots
A great example of being in a situation in which you need to create a summarized data set is when you want to create an interaction plot. We'll take a look at such an example in this section. If you haven't taken a course on analysis of variance yet, such as Stat 502, and therefore don't yet know what an interaction plot is, don't fret. You'll get the basic idea here.
The following program uses data from the ICDB Background data set to illustrate how to create a simple plot to depict whether an interaction exists between two class variables, sex and race, when the analysis variable of interest is education level (ed_level):
PROC SORT data=icdb.back out=back; by sex race; RUN; PROC MEANS data=back noprint; by sex race; var ed_level; output out=meaned mean=mn_edlev; RUN; PROC PRINT; title 'Mean Education Level for Sex and Race combinations'; RUN; PROC PLOT data=meaned; title 'Interaction Plot of SEX, RACE, and Mean Education Level'; plot mn_edlev*race=sex; RUN;
Let's review the code. The SORT procedure merely prepares the Background data set for BY-group processing. The MEANS procedure calculates the mean education level ("var ed_level") for each sex and race combination ("by sex race"). The OUTPUT statement tells SAS to dump the results into a new data set called meaned. The PRINT procedure of course tells SAS to print the meaned data set, which as you'll see when you run the code, looks like this:
Mean Educational Level for Sex and race combinations
As we'd expect, the data set contains one observation for each sex and race combination. The primary variable is mn_edlev, the average education level of the subjects of that sex and race combination. Once the meaned data set is created, all we need to do is use the means in the data set to create an interaction plot. The PLOT procedure tells SAS to plot the mean education level (mn_edlev) on the y-axis and race (race) on the x-axis. The "=sex" part of the PLOT statement tells SAS to label the x-y (race-edlevel) coordinates with the value of the variable sex.
Before you run this program, you'll need to right-click on the link for the background data set to download and save it to your computer. You should store it in the same location that you've saved the permanent icdb.hem2 data set. Launch and run the SAS program, and review the resulting plot. You should see the interaction plot as advertised.
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.
11.7 - Summary11.7 - Summary
In this lesson, we learned about three procedures available in SAS — UNIVARIATE, MEAN and SUMMARY — to calculate basic descriptive statistics.
The homework for this lesson will give you practice with these techniques.