Chapter 44: 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 on page 1030.

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

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. Output 44.1 shows the log that results from running this PROC SORT step. Output 44.2 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; 
Output 44.1: SAS Log Generated by PROC SORT
start example
 NOTE: There were 6 observations read from the data set WORK.EMPLOYEE.  NOTE: The data set WORK.EMPLOYEE has 6 observations and 3 variables.  NOTE: PROCEDURE SORT used:        real time           0.01 seconds        cpu time            0.01 seconds 
end example
 
Output 44.2: Observations Sorted by the Values of One Variable
start example
 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 
end example
 

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 Example 2 on page 1033.

Output 44.3: Observations Sorted by the Values of Three Variables
start example
 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 
end example
 



Base SAS 9.1.3 Procedures Guide (Vol. 1)
Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
ISBN: 1590472047
EAN: 2147483647
Year: 2004
Pages: 260

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net