Previous Page | Next Page

The SORT Procedure

Overview: SORT Procedure


What Does the SORT Procedure Do?

The SORT procedure orders SAS data set observations by the values of one or more character or numeric variables. The SORT procedure either replaces the original data set or creates a new data set. PROC SORT produces only an output data set. For more information, see Procedure Output.

Operating Environment Information:   The sorting capabilities that are described in this chapter are available for all operating environments. In addition, if you use the HOST value of the SAS system option SORTPGM=, you might be able to use other sorting options that are available only for your operating environment. Refer to the SAS documentation for your operating environment for information about other sorting capabilities.  [cautionend]


Sorting SAS Data Sets

In the following example, the original data set was in alphabetical order by last name. PROC SORT replaces the original data set with a data set that is sorted by employee identification number. SAS Log Generated by PROC SORT shows the log that results from running this PROC SORT step. Observations Sorted by the Values of One Variable shows the results of the PROC PRINT step. The statements that produce the output follow:

proc sort data=employee;
   by idnumber;
run;

proc print data=employee;
run;

SAS Log Generated by PROC SORT

NOTE: There were six observations read from the data set WORK.EMPLOYEE.
NOTE: The data set WORK.EMPLOYEE has six observations and three variables.
NOTE: PROCEDURE SORT used:
      real time           0.01 seconds
      cpu time            0.01 seconds

Observations Sorted by the Values of One Variable

                         The SAS System                        1

                 Obs    Name          IDnumber

                  1     Belloit         1988  
                  2     Wesley          2092  
                  3     Lemeux          4210  
                  4     Arnsbarger      5466  
                  5     Pierce          5779  
                  6     Capshaw         7338  

The following output shows the results of a more complicated sort by three variables. The businesses in this example are sorted by town, then by debt from highest amount to lowest amount, then by account number. For an explanation of the program that produces this output, see Sorting in Descending Order.

Observations Sorted by the Values of Three Variables

                        Customers with Past-Due Accounts                       1
                     Listed by Town, Amount, Account Number

                                                                  Account
      Obs    Company                   Town              Debt      Number

        1    Paul's Pizza              Apex              83.00      1019 
        2    Peter's Auto Parts        Apex              65.79      7288 
        3    Watson Tabor Travel       Apex              37.95      3131 
        4    Tina's Pet Shop           Apex              37.95      5108 
        5    Apex Catering             Apex              37.95      9923 
        6    Deluxe Hardware           Garner           467.12      8941 
        7    Boyd & Sons Accounting    Garner           312.49      4762 
        8    World Wide Electronics    Garner           119.95      1122 
        9    Elway Piano and Organ     Garner            65.79      5217 
       10    Ice Cream Delight         Holly Springs    299.98      2310 
       11    Tim's Burger Stand        Holly Springs    119.95      6335 
       12    Strickland Industries     Morrisville      657.22      1675 
       13    Pauline's Antiques        Morrisville      302.05      9112 
       14    Bob's Beds                Morrisville      119.95      4998 

Previous Page | Next Page | Top of Page