Difference between "Where" and "Having" in Proc SQL


What is the difference between the "Where" and "Having" statements in Proc SQL ?


Common but only partially correct answer:

Where uses parent variable for sub-setting, while Having is used for sub-setting data on the basis of calculated variables.  


In most of my interviews, I follow this up with the question  "So can we use the parent variable in the "Having" statement as well ?"

Most of the candidates answer :  "NO"

... Blunder ...

So here comes the correct answer for the same.

Answer to Impress:


"Where" is used for sub-setting the data before processing it (during the input buffer) and hence can use only Parent variables, however "Having" works post processing (PDV) and can therefore use both the parent as well as derived (calculated) variables.

It's a different matter that using parent variables in "Having" statement for sub-setting is inefficient practice.

Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.