Skip to content

Instantly share code, notes, and snippets.

@abhishekdagarit
Last active September 22, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishekdagarit/232301981ed959f4440c40b495ccf3f5 to your computer and use it in GitHub Desktop.
Save abhishekdagarit/232301981ed959f4440c40b495ccf3f5 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment