Sorting Data

Overview

By default, PROC PRINT lists observations in the order in which they appear in your data set. To sort your report based on values of a variable, you must use PROC SORT to sort your data before using the PRINT procedure to create reports from the data.
The SORT procedure
  • rearranges the observations in a SAS data set
  • creates a new SAS data set that contains the rearranged observations
  • replaces the original SAS data set by default
  • can sort on multiple variables
  • can sort in ascending or descending order
  • does not generate printed output
  • treats missing values as the smallest possible values.
General form, simple PROC SORT step:
PROC SORT DATA=SAS-data-set<OUT=SAS-data-set>;
BY <DESCENDING> ...

Get SAS Certification Prep Guide: Base Programming for SAS 9, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.