Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Using the ‘PRESORTED’ Option with Proc SORT in SAS 9.2

In SAS 9.2 Proc SORT the 'PRESORTED' option has been added; we can use this option if we believe that our data is already sorted, causing SAS to simply verify that our assumption is correct rather than re-sorting the data.

proc contents;

If we examine the partial output from Proc CONTENTS for this data set, we can see that the sorted flag is set to 'NO'

The CONTENTS Procedure
Observations              11
Variables                 2
Indexes                   0
Observation Length        16
Deleted Observations      0
Compressed                NO
Sorted                    NO 

Using the 'Presorted' option in PROC SORT, the log shows that SAS only verified that the data was in the correct order:

proc sort data=buy presorted;
    by date;
9 proc sort data=buy presorted; 10 by date; 11 run;
NOTE: Sort order of input data set has been verified. NOTE: There were 11 observations read from the data set WORK.BUY. NOTE: Input data set is already sorted, no sorting done.

If, however, it turns out that data is not sorted as we supposed then the sort will be automatically performed and a note written to the log.

proc sort data=buy presorted;
    by amount;
14 proc sort data=buy presorted; 15 by amount; 16 run;
NOTE: Input data set is not in sorted order. NOTE: There were 11 observations read from the data set WORK.BUY. NOTE: The data set WORK.BUY has 11 observations and 2 variables.

Caution should be exercised when using this option when directly reading data into Proc SORT from a DBMS. Since external databases can generally not be relied on to return data in the same order each time, this means that although we will still get our data sorted if required, data with the same values for our ‘by’ variables may be returned in a different order each time.