Consider using the CLASS statement on a MEANS or SUMMARY rather than Sort.
The class statement on a PROC
MEANS or SUMMARY allows observations to be grouped according to the
given variable names in the same way that a BY statement does. The
major differences are that a dataset does not need to be sorted
according to the CLASS variables, but for datasets with a high number
of unique values of class variables this may become inefficient because
the result of computations are held in memory rather than output to
disk as soon as a group boundary is found.
There is therefore a trade-off
between CPU saved by not using the sort, and that used with the CLASS
statement. There are no strict guidelines for when to use CLASS rather
than BY, but bear in mind that there is a theoretical limit of 32,767
combinations of class variables.