Returns a character value of an expression based on whether the expression is true, false, or missing
Category: Character
IFC ( logical-expression , value-returned-when-true , value-returned-when-false
<, value-returned-when-missing >)
logical-expression
specifies a numeric expression.
value-returned-when-true
specifies a character expression that is returned when the value of logical-expression is true.
value-returned-when-false
specifies a character expression that is returned when the value of logical-expression is false.
value-returned-when-missing
specifies a character expression that is returned when the value of logical-expression is missing.
The IFC function uses conditional logic that enables you to select among several different values based on the value of a logical expression.
IFC evaluates the first argument, logical-expression . If logical-expression is true (that is, not zero and not missing), then IFC returns the value in the second argument. If logical-expression is a missing value, and you have a fourth argument, then IFC returns the value in the fourth argument. If logical-expression is false, IFC returns the value in the third argument.
The IFC function is useful in DATA step expressions, and even more useful in WHERE clauses and other expressions where it is not convenient or possible to use an IF/THEN/ELSE construct.
The IFC function is similar to the IFN function except that IFC returns a character value while IFN returns a numeric value.
In the following example, IFC evaluates the expression grade > 80 to implement the logic that determines the performance of several members on a team. The results are written to the SAS log.
data _null_; input name $ grade; performance = ifc(grade>80, 'Pass ', 'Needs Improvement'); put name= performance=; datalines; John 74 Kareem 89 Kati 100 Maria 92 ; run;
name=John performance=Needs Improvement name=Kareem performance=Pass name=Kati performance=Pass name=Maria performance=Pass
This example uses an IF/THEN/ELSE construct to generate the same output that is generated by the IFC function. The results are written to the SAS log.
data _null_; input name $ grade; if grade>80 then performance='Pass '; else performance = 'Needs Improvement'; put name= performance=; datalines; John 74 Sam 89 Kati 100 Maria 92 ; run;
name=John performance=Needs Improvement name=Sam performance=Pass name=Kati performance=Pass name=Maria performance=Pass
Functions:
'IFN Function' on page 586