# Mean Median and Mode in SAS – Row wise and column wise

In order to calculate Mean Median and Mode in SAS we will be using mean() and median() function. In order to calculate row wise mean in SAS we will be using mean() function in SAS Datastep. In order to calculate column wise mean in SAS we will be using mean() function in proc sql. In order to calculate row wise median in SAS we will be using median() function in SAS Datastep. In order to calculate column wise median in SAS we will be using median() function in proc sql. Mode in SAS is calculated using univariate function.

Let’s see an example of each.

• To calculate Row wise mean in SAS we will be using mean() function in SAS Datastep.
• To calculate Column wise mean in SAS we will be using mean() function in PROC SQL
• To calculate Row wise median in SAS we will be using median() function in SAS Datastep.
• To calculate Column wise median in SAS we will be using median() function in PROC SQL
• Mode in SAS is calculated using proc univariate

So we will be using EMP_DET Table in our example

#### Row Mean in SAS – Row wise Mean- Mean in SAS

We will be using mean() function in SAS datastep to calculate row wise mean.

``` /*   Row wise mean */

data EMP_DET1;
set EMP_DET;
mean_salary = mean(salary_2020,salary_2019,salary_2018);
run;

```

So the resultant table with row wise mean calculated will be

#### Column Mean in SAS – Populate Mean of the column in SAS

We will be using mean() function in PROC SQL to calculate column wise mean.

```/* populate column wise mean */

proc sql;
create table EMP_DET1 as(select*,mean(salary_2020) as mean_salary from EMP_DET);
run;

```

So the resultant table with column wise mean calculated will be

#### Row median in SAS – Row wise Median- Median in SAS

We will be using median() function in SAS Datastep to calculate row wise median.

```/* Row wise median */

data EMP_DET1;
set EMP_DET;
median_salary = median(salary_2020,salary_2019,salary_2018);
run;

```

So the resultant table with row wise median calculated will be

#### Column Median in SAS – Populate Median of Column in SAS

We will be using median() function in proc sql to calculate column wise median.

```/* populate column wise median */

proc sql;
create table EMP_DET1 as(select*,median(salary_2020) as median_salary from EMP_DET);
run;

```

So the resultant table with column wise median calculated will be

#### Mode of a Column in SAS – Mode in SAS

We will be using  proc univariate to calculate column wise mode.

```/* Get column wise mode */

proc univariate data=EMP_DET1;
var salary_2020;
run;

```

So the mode of the column will be

## Author

• With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.