abhishekdagarit
9/21/2017 - 3:01 PM

Sort function in SAS

Sort function in SAS

Sort function in SAS

By

Basic sort function. Uses by.

proc sort data=work.test;
by Salary;
run;

Class

Alternative for by is class. We can use either by or class.

proc sort data=work.test;
class Salary;
run;

The default is ascending/alphabatical value. For reverse order use descending

Sort in descending order

proc sort data=work.test;
by descending Salary;
run;

Sort in ascending order

proc sort data=work.test;
by Salary;
run;

Sort in alphabatical order

proc sort data=work.test;
by name;
run;

Sort in reverse alphabatical order

proc sort data=work.test;
by descending name;
run;

Sorting by multiple variables. Simply add two variables instead of one. Sequence matters.

proc sort data=work.test;
by post salary;
run;

Sort post then descending salary

proc sort data=work.test;
by post descending salary;
run;

Sort descending post and then salary

proc sort data=work.test;
by descending post salary;
run;

Sort descending post then descending salary

proc sort data=work.test;
by descending post descending salary;
run;