Home » Arithmetic Mean in SAS

Arithmetic Mean in SAS

by Online Tutorials Library

What is Arithmetic Mean?

In general mathematics, Arithmetic Mean or Mean is the value obtained from the calculation of values of a set by a specific formula.

For Example:

In the following example, we need to calculate the arithmetic mean of a set which contains the age of 5 students.

Here we can see, the Arithmetic Mean is 9. This Mean is obtained from the sum of all values of the above set by applying the specific formula.

Arithmetic Mean in SAS

In SAS, we can calculate the Arithmetic Mean of all variables or only required variables of a dataset. To calculate Arithmetic Mean, SAS provides a procedure called PROC MEANS. SAS also provides the facility to find the Mean of groups by creating a group from specific variables.

Syntax:

Where,

  • DATASET: It is the name of the dataset which is used to find the Mean.
  • Variables: These are the names of the variables which are used for Mean operation.

Now, we are going to learn components of the SAS Arithmetic Mean such as Mean of the whole data set, specific variables , and a group of specific variables by using specific procedures and statements.

Following is the list of components of Arithmetic Mean with procedure and statements:

  • Mean of a Dataset by PROC MEAN
  • Mean of Specific Variables by VAR Statement
  • Mean of Group of Specific Variables by Class Statement

Mean of a Dataset by PROC MEAN

We can calculate the Mean of the whole data set by providing only its name into the PROC MEAN. We do not need to mention any variable name because it will be calculated by supplying only the dataset name.

Example:

In the below example, we are going to calculate the Mean of all the numeric variables in the SAS dataset citiday, which is already available in the SAS help library. We will also calculate the sum of those variables.

Execute the above code in SAS Studio:

Arithmetic Mean

Output:

Arithmetic Mean 2

As we can see in the output, Mean and sum of data set citiday has been calculated with 2 digits decimal place.

How to Display Different Decimal Places?

We can display the Mean and Sum of the data set with the 0 and maximum required decimal places. In the below example, we are going to display the result with 0 or no decimal places.

Example:

Execute the above code in SAS Studio:

Arithmetic Mean 3

Output:

Arithmetic Mean 4

As per the above output, the result has been displayed with 0 or no decimal places.

Now, we are taking 3 decimal places in the below example. You can choose any number of decimal place as per the requirement.

Execute the above code in SAS Studio:

Arithmetic Mean 5

Output:

Arithmetic Mean 6

As per the above output, the result of Mean and Sum has been displayed with 3 decimal places.

Mean of Specific Variables by VAR Statement

Sometimes we need to calculate the Mean of only specific variables for our analysis. We can calculate the Mean of specific variables by providing their names in the VAR statement. Let us understand it through an example:

Example:

In the following example, we are going to calculate the Mean of some specific variables, i.e., SNYDJCM SNYSECM DFXWUK90 from the data set cityday, which is already available in the SAS help library.

Execute the above code in SAS Studio:

Arithmetic Mean 7

Output:

Arithmetic Mean 8

As per the above output, the Mean of only selected variables has been calculated.

Mean of a group of Specific Variables by Class Statement

In the SAS data set, each variable is different from others in some aspects such as in dataset cars, the price of a Porsche can be different from Toyota. Thus, it is more suitable to do a separate analysis for each car maker. So, for separate analysis, we can create a class of only required variables by using the CLASS statement. Let us understand it through an example:

Example:

In the following example, we are going to calculate the Mean of variable “horsepower” of the cars data set, so that we can categorize cars of various companies as per their sustainable power. To include cars, we are creating a Class by using Class statement with variables Make (which contains the name of car producing companies) and Type (which contain car models launched by the particular company).

Note: Cars data set is already available in SAS help library, kindly consider it for more clarity.

Execute the above code in SAS Studio:

Arithmetic Mean 9

Output:

Arithmetic Mean 10

As we can see in the output, Mean of the data set cars has been calculated on the basis of horsepower, make, and type variables.


Next TopicCross Tabulation

You may also like