The UNIVARIATE Procedure |
This example illustrates how to save summary statistics in an output data set. The following statements create a data set named Belts, which contains the breaking strengths (Strength) and widths (Width) of a sample of 50 automotive seat belts:
data Belts; label Strength = 'Breaking Strength (lb/in)' Width = 'Width in Inches'; input Strength Width @@; datalines; 1243.51 3.036 1221.95 2.995 1131.67 2.983 1129.70 3.019 1198.08 3.106 1273.31 2.947 1250.24 3.018 1225.47 2.980 1126.78 2.965 1174.62 3.033 1250.79 2.941 1216.75 3.037 1285.30 2.893 1214.14 3.035 1270.24 2.957 1249.55 2.958 1166.02 3.067 1278.85 3.037 1280.74 2.984 1201.96 3.002 1101.73 2.961 1165.79 3.075 1186.19 3.058 1124.46 2.929 1213.62 2.984 1213.93 3.029 1289.59 2.956 1208.27 3.029 1247.48 3.027 1284.34 3.073 1209.09 3.004 1146.78 3.061 1224.03 2.915 1200.43 2.974 1183.42 3.033 1195.66 2.995 1258.31 2.958 1136.05 3.022 1177.44 3.090 1246.13 3.022 1183.67 3.045 1206.50 3.024 1195.69 3.005 1223.49 2.971 1147.47 2.944 1171.76 3.005 1207.28 3.065 1131.33 2.984 1215.92 3.003 1202.17 3.058 ; run;
The following statements produce two output data sets containing summary statistics:
proc univariate data=Belts noprint; var Strength Width; output out=Means mean=StrengthMean WidthMean; output out=StrengthStats mean=StrengthMean std=StrengthSD min=StrengthMin max=StrengthMax; run;
When you specify an OUTPUT statement, you must also specify a VAR statement. You can use multiple OUTPUT statements with a single procedure statement. Each OUTPUT statement creates a new data set with the name specified by the OUT= option. In this example, two data sets, Means and StrengthStats, are created. See Output 4.7.1 for a listing of Means and Output 4.7.2 for a listing of StrengthStats.
Summary statistics are saved in an output data set by specifying keyword=names after the OUT= option. In the preceding statements, the first OUTPUT statement specifies the keyword MEAN followed by the names StrengthMean and WidthMean. The second OUTPUT statement specifies the keywords MEAN, STD, MAX, and MIN, for which the names StrengthMean, StrengthSD, StrengthMax, and StrengthMin are given.
The keyword specifies the statistic to be saved in the output data set, and the names determine the names for the new variables. The first name listed after a keyword contains that statistic for the first variable listed in the VAR statement; the second name contains that statistic for the second variable in the VAR statement, and so on.
The data set Means contains the mean of Strength in a variable named StrengthMean and the mean of Width in a variable named WidthMean. The data set StrengthStats contains the mean, standard deviation, maximum value, and minimum value of Strength in the variables StrengthMean, StrengthSD, StrengthMax, and StrengthMin, respectively.
See the section OUT= Output Data Set in the OUTPUT Statement for more information about OUT= output data sets.
A sample program for this example, uniex06.sas, is available in the SAS Sample Library for Base SAS software.
Copyright © SAS Institute, Inc. All Rights Reserved.