Sum Function in SAS – Row wise and column wise sum in SAS

In order to calculate sum of the rows and sum of the columns in SAS we will be using SUM() function. In order to calculate row wise sum in SAS we will be using SUM() function in SAS Datastep. In order to calculate column wise sum in SAS we will be using SUM() function in proc sql. Let’s see an example of each.

  • To calculate Row wise sum in SAS we will be using SUM() function in SAS Datastep.
  • To Calculate Column wise sum in SAS we will be using SUM() function in PROC SQL

So we will be using EMP_DET Table in our example

Sum Function in SAS – Row wise and column wise sum in SAS 1

 

 

Sum Function in SAS – Row wise sum in SAS

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

/*  Row wise sum */ 

data EMP_DET1; 
set EMP_DET; 
sum_salary = sum(salary_2020,salary_2019,salary_2018); 
run;

So the resultant table with row wise sum calculated will beSum Function in SAS – Row wise and column wise sum in SAS 2

 

 

 

Column Sum in SAS – Populate Sum of the column in SAS

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

/*  populate column wise sum */ 

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

So the resultant table with column wise sum (salary_2020) calculated will be
Sum Function in SAS – Row wise and column wise sum in SAS 3

 

                                                                                 

Author

  • Sridhar Venkatachalam

    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.

    View all posts