Plotting Sums and Means of Numeric Variables - SAS Programming

So far, you have seen bar charts where the Y axis represents the frequency count, or percentage,for values or ranges displayed on the X axis.PROC CHART can also provide charts where the Y axis represents the mean or sum of a numeric variable for each value of another variable shown on the X axis.

For example, suppose you want to see the total (SUM) of the variable QUANTITY for each region of the country from the SALES data set.You use the SUMVAR= option to select the numeric variable on which to compute the sum or mean,and the TYPE= option to indicate the desired statistic.The default type is SUM, but you should always include a TYPE= option whenever you use the SUMVAR= option. So,to produce the chart just described, use the following code:

Example

PROC CHART DATA=SALES;
TITLE 'Adding Options SUMVAR= and TYPE=';
VBAR REGION / SUMVAR=QUANTITY TYPE=SUM;
RUN;

The resulting chart follows:

Output from Example - Plotting Sums and Means of Numeric Variables

Output from Example  - Plotting Sums and Means of Numeric Variables

The bars here represent the sum of the variable QUANTITY for each of the regions. If you had done this using an HBAR statement, you could have requested the actual sums to print alongside of the bars; if you used TYPE=MEAN, you could have requested the mean statistic.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics