IFNULL Function

Checks the value of the first expression and, if it is null or a SAS missing value, returns the second expression.

Category: Special
Returned data type: Any data type, depending on the context

Syntax

Arguments

expression

specifies any valid expression.

Data type All data types are valid.
See <sql-expression>
FedSQL Expressions

Details

The IFNULL function returns the first expression if it is not null. You can use the IFNULL function to replace a null or SAS missing value value with another value.

Comparisons

The NULLIF expression compares two expressions and returns a null value if the two expressions are equal. The IFNULL function checks the value of the first expression and if it is null, returns the second expression; otherwise, returns the first expression.

Example

In the table WORLDTEMPS, the city for China in the last row contains a missing value.
Statements
Results
select ifnull(AvgHigh, 0) as 
"AvgHigh: 0 indicates null/missing" 
from worldtemps;
AvgHigh: 0 indicates
       null/missing
90
70
86
90
97
83
76
89
90
89
0
78

See Also

Expressions: