In reply to Rick Wicklin.

If the dataset has an index on the desired BY variable, then the engine with the WHERE= will use the index to pluck only the rows it needs. This works best, of course, when the dataset is sorted on the BY variable, but should help even when it isn't.