Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Writing Efficient Testing Conditions

When you code a complex test condition, think about the order in which you specify the subconditions. For example: 

              if age ge 80 or sex=’M’;

is going to take longer on average to execute than:

             if sex=’M’ or age ge 80;

Why?  Well if our data was a random sample from the population, we would expect about half of the subjects in our dataset to be male, but only a small fraction of them to be 80 or over. If we test the sex first, half the time we won’t need to test the age at all as the observation will have already been included, as a result this technique has become known as Boolean short circuiting.


             if hometown in (“Whitby”, “Leeds”, “Bradford”);

could be made more efficient by re-ordering the towns. Whitby is a much smaller town than the other two, so it makes sense to test for Leeds or Bradford first as SAS will stop testing once a true condition has been found.
When conditions are ANDed rather than ORed together, similar but opposite considerations apply.

             if age ge 80 and sex=’M’;

 is the correct way round, since a high proportion of candidates will fail the first part of the test, so that we won’t need to check the second.