Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS arithmetic average


May 27, 2021 SAS


Table of contents


Arithmetic averages are values obtained by mething the values of numeric variables and then divideing the values by the number of variables. I t is also known as the mean. T he SAS arithmetic average is calculated using PROC MEANS. U sing this SAS program, we can find the average of all variables or some variables of the dataset. W e can also form groups and find the average value of variables that are specific to the values of that group.

Grammar

The basic syntax for calculating arithmetic averages in SAS is:

PROC MEANS DATA = DATASET;
CLASS Variables ;
VAR Variables;

The following is a description of the parameters used:

  • DATASET is the name of the dataset used.
  • A variable is the name of a variable in the data set.

The average value of the dataset

The average value of each numeric variable in the dataset is calculated by using proC to provide only the dataset name without using any variables.

Cases

In the following example, we find the average of all the numeric variables in the SAS data set called CARS. W e specify the maximum number of digits after the scale to 2 and find the sum of these variables.

PROC MEANS DATA = sashelp.CARS Mean SUM MAXDEC=2;
RUN;

Select the average value of the variable

We can get the average of some variables by providing their names in the var option.

Cases

Below, we calculate the average of the three variables.

PROC MEANS DATA = sashelp.CARS mean SUM MAXDEC=2 ;
var horsepower invoice EngineSize;
RUN;

When we execute the above code, we get the following output:

SAS arithmetic average

Average by category

We can find the average of numeric variables by using some other variables to aggregate them into groups.

Cases

In the following example, we find the average of each type of variable horsepower under each model.

PROC MEANS DATA = sashelp.CARS mean SUM MAXDEC=2;
class make type;
var horsepower;
RUN;

When we execute the above code, we get the following output:

SAS arithmetic average