IFC Function


Returns a character value of an expression based on whether the expression is true, false, or missing

Category: Character

Syntax

IFC ( logical-expression , value-returned-when-true , value-returned-when-false

  • <, value-returned-when-missing >)

Arguments

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.

Details

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.

Comparisons

The IFC function is similar to the IFN function except that IFC returns a character value while IFN returns a numeric value.

Examples

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; 
Output 4.25: Partial SAS Log-IFC Function
start example
 name=John performance=Needs Improvement  name=Kareem performance=Pass  name=Kati performance=Pass  name=Maria performance=Pass 
end example
 

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; 
Output 4.26: Partial SAS Log-IF/THEN/ELSE Construct
start example
 name=John performance=Needs Improvement  name=Sam performance=Pass  name=Kati performance=Pass  name=Maria performance=Pass 
end example
 

See Also

Functions:

  • 'IFN Function' on page 586




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net