Thanks for the lesson, @RogerSpeas. As I mentioned, I don't write a lot of SQL. Guess I had hoped with the correlated subquery that the optimizer might be smart enough to sort both tables (if not indexed), and then approach the correlated sub-query with something like the double-DOW loop approach that Astounding used (point being to process each by-group in turn, so would only need one pass of each dataset after the sorts). But that's probably hoping for too much. Correlated sub-queries make me scratch my head. And I like your last solution, with joining on the pre-summarized table. That's the kind of SQL where I don't have to scratch my head, and I think "wow, it's fun to read SQL, because all you have to think about is sets." I spent so much time learning the intracies of the DATA step processes for merges and BY group interleaving and DOW loops.... it took me a long time to get over the fact that with SQL, I wasn't telling SAS how to do something, I was telling SAS what I wanted done. Cheers, --Q.
... View more