Previous Page | Next Page

Functions and CALL Routines

IFC Function



Returns a character value based on whether an expression is true, false, or missing.
Category: Character
Restriction: I18N Level 2

Syntax
Arguments
Details
Length of Returned Variable
The Basics
Comparisons
Examples
See Also

Syntax

IFC(logical-expression, value-returned-when-true, value-returned-when-false <,value-returned-when-missing>)

Arguments

logical-expression

specifies a numeric constant, variable, or expression.

value-returned-when-true

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

value-returned-when-false

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

value-returned-when-missing

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


Details


Length of Returned Variable

In a DATA step, if the IFC function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes.


The Basics

The IFC function uses conditional logic that enables you to select among several 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. Otherwise, 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;

Partial SAS Log: IFC Function

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;

Partial SAS Log: IF/THEN/ELSE Construct

name=John performance=Needs Improvement
name=Sam performance=Pass
name=Kati performance=Pass
name=Maria performance=Pass

See Also

Functions:

IFN Function

Previous Page | Next Page | Top of Page