# Sort function in SAS
# By
Basic sort function. Uses **by**.
```sas
proc sort data=work.test;
by Salary;
run;
```
# Class
Alternative for by is class. We can use either by or class.
```sas
proc sort data=work.test;
class Salary;
run;
```
The default is **ascending/alphabatical** value. For reverse order use **descending**
Sort in **descending** order
```sas
proc sort data=work.test;
by descending Salary;
run;
```
Sort in **ascending** order
```sas
proc sort data=work.test;
by Salary;
run;
```
Sort in **alphabatical** order
```sas
proc sort data=work.test;
by name;
run;
```
Sort in **reverse alphabatical** order
```sas
proc sort data=work.test;
by descending name;
run;
```
Sorting by **multiple variables**. Simply **add two variables** instead of one. **Sequence** matters.
```sas
proc sort data=work.test;
by post salary;
run;
```
Sort post then descending salary
```sas
proc sort data=work.test;
by post descending salary;
run;
```
Sort descending post and then salary
```sas
proc sort data=work.test;
by descending post salary;
run;
```
Sort descending post then descending salary
```sas
proc sort data=work.test;
by descending post descending salary;
run;
```