Maximum and Minimum in SAS – Row wise and column wise

In order to calculate Maximum and Minimum in SAS we will be using max() and min() function. In order to calculate row wise maximum in SAS we will be using max() function in SAS Datastep. In order to calculate column wise maximum in SAS we will be using max() function in proc sql. In order to calculate row wise minimum in SAS we will be using min() function in SAS Datastep. In order to calculate column wise minimum in SAS we will be using min() function in proc sql. Let’s see an example of each.

  • To calculate Row wise maximum in SAS we will be using max() function in SAS Datastep.
  • To calculate Column wise maximum in SAS we will be using max() function in PROC SQL
  • To calculate Row wise minimum in SAS we will be using min() function in SAS Datastep.
  • To calculate Column wise minimum in SAS we will be using min() function in PROC SQL

So we will be using EMP_DET Table in our example

Maximum and Minimum in SAS – Row wise and column wise 1

 

Row Maximum in SAS – Row wise Maximum- Maximum in SAS

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

/* Row wise maximum */ 

data EMP_DET1; 
set EMP_DET; 
max_salary = max(salary_2020,salary_2019,salary_2018); 
run;

So the resultant table with row wise maximum calculated will be
Maximum and Minimum in SAS – Row wise and column wise 2

 

 

Column Maximum in SAS – Populate Maximum value of column in SAS

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

/* populate column wise maximum */ 

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

So the resultant table with column wise maximum calculated will be
Maximum and Minimum in SAS – Row wise and column wise 3

 

 

Row Minimum in SAS – Row wise Minimum- Minimum in SAS

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

/* Row wise minimum */ 

data EMP_DET1; 
set EMP_DET; 
min_salary = min(salary_2020,salary_2019,salary_2018); 
run;

So the resultant table with row wise minimum calculated will be
Maximum and Minimum in SAS – Row wise and column wise 4

 

 

Column Minimum in SAS – Populate Minimum value of column in SAS

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

/* populate column wise minimum */ 

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


So the resultant table with column wise minimum calculated will be
Maximum and Minimum in SAS – Row wise and column wise 5

 

                                                                                               

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.