Sort Table in SAS – PROC SORT

In order to Sort Table in SAS in Ascending order or descending order we will be using PROC SORT statement. Sort by single column and Sort by multiple column in SAS is also accomplished using PROC SORT.  Example of PROC SORT and remove duplicates using NODUPKEY, NODUP

  • Sort table by single column in SAS – Descending order
  • Sort table by multiple columns in SAS – Descending order
  • Sort table by single column in SAS – Ascending order
  • Sort table by multiple columns in SAS – Ascending order
  • Sort table and remove duplicate key in SAS – PROC SORT NODUPKEY
  • Sort table and remove duplicate in SAS – PROC SORT NODUP

We will be using the table name CARS.

Sort Table in SAS – PROC SORT 1

 

Sort table by single column – PROC SORT

Sort table by single column (make) in SAS is accomplished using PROC SORT and the result is copied to the table “cars_sorted“ as shown below


/* sort table by single column */

proc sort data=cars out=cars_sorted; 
by make; 
run;

Sort Table in SAS – PROC SORT 2

 

Sort table by single column – Descending Order  – PROC SORT

Sort table in descending order by single column (make) in SAS is accomplished using PROC SORT along with descending keyword and the result is copied to the table “cars_sorted“ as shown below

/* sort table by single column */

proc sort data=cars_sorted; 
by descending make; 
run;


Sort Table in SAS – PROC SORT 3

 

Sort table by multiple column – PROC SORT

Sort table by multiple columns (make , price) in SAS is accomplished using PROC SORT and the result is copied to the table “cars_sorted“ as shown below

/* sort by multiple column */ 

proc sort data=cars_sorted; 
by make price; 
run;

Sort Table in SAS – PROC SORT 4

 

Sort and remove Duplicate rows – PROC SORT NODUP

Sort table by single columns (make ) in SAS is accomplished using PROC SORT  and duplicate rows are removed using NODUP keyword and the result is copied to the table “cars_sorted“ as shown below

/* sort and remove duplicate rows */ 

proc sort data=cars out=cars_sorted NODUP; 
by make; 
run;

Sort Table in SAS – PROC SORT 5

 

 

Sort and remove Duplicate Key- PROC SORT NODUPKEY

Sort table by single columns (make ) in SAS is accomplished using PROC SORT  and duplicate key is removed using NODUPKEY keyword and the result is copied to the table “cars_sorted“ as shown below

/* sort and remove duplicate KEY - which is BY variable */ 

proc sort data=cars out=cars_sorted NODUPKEY; 
by make; 
run;

Sort Table in SAS – PROC SORT 6