The general idea is this.
The macro loops through &MAX times, each time selecting another item to search for and then running a DATA step.
It ought to be possible to reduce this to two steps. So if &MAX is large this is a large savings, but from this side it's not possible to determine that.
The first step in the new design gathers ALL the terms you need to search for from HRLIST. It's probably not a job for SQL, but rather a job for a single DATA step.
Then the second step would be a DATA step that reads in the search terms, and sets up FLAG accordingly.
That's the general idea. It's difficult to say more without knowing more about your data.
... View more