Returns a numeric value based on whether an expression is true, false, or missing.

Category: | Numeric |

Restriction: | I18N Level 2 functions are designed for use with SBCS, DBCS, and MBCS (UTF8). |

specifies a numeric constant, variable, or expression.

specifies a numeric constant, variable, or expression that is returned when the value of logical-expression is true.

specifies a numeric constant, variable, or expression that is returned when the value of logical-expression is false.

The IFN function uses
conditional logic that enables you to select among several values
based on the value of a logical expression.

IFN evaluates the first
argument, then logical-expression. If logical-expression is
true (that is, not zero and not missing), then IFN returns the value
in the second argument. If logical-expression is a missing value, and you have a fourth argument, then IFN returns
the value in the fourth argument. Otherwise, if logical-expression is false, IFN returns the
value in the third argument.

In the following example,
IFN evaluates the expression

`TotalSales > 10000`

. If total sales exceeds $10,000, then the sales commission is 5%
of the total sales. If total sales is less than $10,000, then the
sales commission is 2% of the total sales. data _null_; input TotalSales; commission=ifn(TotalSales > 10000, TotalSales*.05, TotalSales*.02); put commission=; datalines; 25000 10000 500 10300 ; run;

In the following example,
an IF/THEN/ELSE construct evaluates the expression

```
TotalSales
> 10000
```

. If total sales exceeds $10,000, then the
sales commission is 5% of the total sales. If total sales is less
than $10,000, then the sales commission is 2% of the total sales.
In the following example,
a WHERE statement evaluates the expression

```
TotalSales
> 10000
```

. If total sales exceeds $10,000, then the
sales commission is 5% of the total sales. If total sales is less
than $10,000, then the sales commission is 2% of the total sales.
The output shows only those salespeople whose total sales exceed $10,000.
Copyright © SAS Institute Inc. All rights reserved.