As said, when comparing stats I usually go for the CLASS statement. As others have pointed out, BY requires the input data to be sorted. However, if your input data is coming from a database library (and not a SAS data set), PROC MEANS is smart enough to ask for the data in "sorted" order before calculating the stats, so a separate PROC SORT step is not necessary. In fact, with SAS 9.2 and later, PROC MEANS will actually get the database to calculate the basic stats if it can: Avg, Sum, Min, Max and so on -- thus saving lots of I/O within your SAS session. Other "database-aware" procs include FREQ, RANK, SUMMARY/MEANS, REPORT, TABULATE. See this SAS Note for more information. Chris
... View more