Language Reference |

**sorts a matrix by specified columns**

**CALL SORT(***matrix, by<, descend >***)**

The inputs to the SORT call are as follows:

*matrix*- is the input matrix, which is sorted in place by the call.
*by*- is either a numeric matrix of column numbers, or a character
matrix containing the names of columns corresponding to
column labels assigned to
*matrix*by a MATTRIB statement or READ statement. *descend*- is an optional matrix, indicating which columns, if any,
should be descending order. Any
*by*columns not specified as descending will be ascending. If*descend*=*by*, then all*by*columns will be descending; if*descend*is skipped or is a null matrix, then all*by*columns will be ascending.

The SORT call is used to sort a matrix, rearranging its rows
according to the columns and order determined by the *by* and
*descend* inputs. Because the sort is done in place, very little additional
memory space is required. The SORT call is not as fast
as the SORTNDX call for matrices with large rows.
After a matrix has been sorted, the unique combinations of values in the
*by* columns can be obtained from the
UNIQUEBY function.

For example, the following statements produce the matrix , as shown:

m = { 1 1 0, 2 2 0, 1 1 1, 2 2 2}; call sort( m, {1 3}, {3} );

M 1 1 1 1 1 0 2 2 2 2 2 0

Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.