Thursday, 1 December 2016

Difference between WHERE and IF Condition

So Finally we can summarize the contrast of Where as if as :



So can we conclude, Where can be applied everywhere but if only in few case...when why should i waste my energy in learning IF, I can easily spend my life with Where.

Please don't be  judgmental so early, let's solve one last question and see the real contrast between where and IF.



Question:

List out the insured people who has sum assured to claim amount ratio as more than 100.

First let me use If :

Data high_income_11;
set insurance;
If Sum_assured /Claim_amount > 100;
Run;

it works well.

First let's try the same with Where :


Data high_income_11;
set insurance;
Where Sum_assured /Claim_amount > 100;
Run;

Something went wrong !


In this case, if helped me but not Where ... 

Let's understand how If an Where work; Why there is difference between the two:


 Where condition filter the data before input buffer whereas if condition filter the data after PDV.

 Where condition is faster because not all observation have to be read.

 Where statement work only on existing variable, but If can work on derived/calculated variables too.

No comments:

Post a Comment