IFN Function
Returns a numeric value based on whether an expression is true, false, or missing.
| Category: | Numeric |
| Restrictions: | This function is assigned an I18N Level 2 status, and is designed for use with SBCS, DBCS, and MBCS (UTF8). For more information, see Internationalization Compatibility. |
| This function is not valid on the CAS server. |
Syntax
Required Arguments
logical-expression
specifies a numeric constant, variable, or expression.
value-returned-when-true
specifies a numeric constant, variable, or expression that is returned when the value of logical-expression is true.
value-returned-when-false
specifies a numeric constant, variable, or expression that is returned when the value of logical-expression is false.
Optional Argument
value-returned-when-missing
specifies a numeric constant, variable or expression that is returned when the value of logical-expression is missing.
Details
Comparisons
Examples
Example 1: Calculating Commission Using the IFN Function
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 ;
commission=1250 commission=200 commission=10 commission=515
Example 2: Calculating Commission Using an IF/THEN/ELSE Construct
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;
if TotalSales > 10000 then commission = .05 * TotalSales;
else commission = .02 * TotalSales;
put commission=;
datalines;
25000
10000
500
10300
;
commission=1250 commission=200 commission=10 commission=515
Example 3: Calculating Commission Using a WHERE Statement
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.
data sales; input SalesPerson $ TotalSales; datalines; Michaels 25000 Janowski 10000 Chen 500 Gupta 10300 ; data commission; set sales; where TotalSales > 10000; commission = TotalSales * .05; run; proc print data=commission; title 'Commission for Total Sales > 1000'; run;
