MAT SORT sorts a numeric or string array along one dimension. The direction of the sort is in ascending order unless the DES keyword follows the key specifier. For multi-dimensioned arrays, entire rows, columns, etc. are swapped in the ordering process according to the values in the sort key specifier.
The sort key specifier is made up of subscript values and an asterisk "*". The asterisk specifies the dimension to be sorted. The subscript values specify which array elements in that subscript are to be used during the sort. Sub-strings may be specified for string arrays.
The optional "TO vector" syntax stores the new order in a vector, leaving the original array unchanged. The vector is redimensioned to the size of the array dimension sorted. It is compatible with the MAT REORDER statement. It is best if the vector is an INTEGER array.
COMPLEX Arrays
MAT SORT can not sort a complex array since the concept of linear ordering does not apply to the complex plane. A complex array can be sorted indirectly by creating a REORDER vector that sorts the complex array according to some linear property of complex numbers, such as magnitude. In the following example, lines 90 to 110 sort the complex array C(*) according to magnitude. A similar technique can be used for other sorting criteria.