Tuesday, December 9, 2008

DO NOT use IFN in division by Zero

IFN is a compact format for IF/THEN/ELSE. However, it runs with a different manner.

In IFN, all expressions will be evaluated at first. And then logical judgement will be applied and regarding value be returned, while IF/THEN/ELSE need not evaluate all expressions.

data test1;
input a b ;
l=ifn(b>0 , 0 , a/b );
* 'b>0' and 'a/b' will be evaluated, so error occur;
cards;
10 2
6 0
9 3
;

data test2;
input a b;
if b=0 then l=0;
else l=a/b;
cards;
10 2
6 0
9 3
;

No comments: