Help using Base SAS procedures

Using the IFC and IFN functions

New Contributor
Posts: 2

Using the IFC and IFN functions

Hi all,

I am having an issue with the IFC and IFN functions using SAS version 9.1.3.

Based on the SAS documentation, these functions can be used to return 3 different values.

The syntax is written as:

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

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

Just as an example here is some code I have tried out.

I have created the class dataset:

data class;

  input id name $5-9;


  1 Henry

  2 Alice




Then I create the class2 dataset, and use the IFC function to try assign 3 different values for a new variable

data class2;

  set class;



The created dataset looks like this:
The first 2 records look as I expected. However I was expecting the 3rd record to have the answer 'Missing' instead of 'No'. Because this record has a blank value for the variable name

I have tried out various ways of using the IFC and IFN functions, but so far have never managed to get the 3rd expression working to cover missing values

Does anyone know what I am doing wrong?

Or if there is a problem with these functions?

Or has an example of how to correctly use these functions to return seperate values for true, false and missing?

Hope that all makes sense! And ideas would be greatly appreciated



Super Contributor
Posts: 312

Re: Using the IFC and IFN functions

It works in the following instance with numeric and character data, but I can't get it to work for with N=..

DATA Work.TestIfc;

attrib N length = 4

Value length = $ %length(missing);

do N = ., 0, 1, -1;

Value = ifc(N









Super User
Posts: 6,785

Re: Using the IFC and IFN functions


The confusion lies in what IFC examines to determine true / false / missing.  It is NOT looking at the value of NAME.  Rather, it is looking at the truth / falsity of the first argument (name='Henry').  When NAME is Henry, the comparison returns a 1 which SAS interprets as true.  When NAME is anything else (including a blank), the comparison returns a 0 which SAS interprets as false.

As Scott's example illustrates, the first argument would have to return a missing value in order for the fourth argument to kick in.  But a comparison as the first argument will always return 1 or 0.

Good luck.

Posts: 1,460

Re: Using the IFC and IFN functions

Posted in reply to Astounding

Agree with Astounding's nice explanation.

Curious if folks see much benefit to SAS having implemented IFC and IFN with such optional trinary logic?

Just about everywhere else I can think of in SAS, it uses binary logic.  Even in PROC SQL, where many SQL implementations use trinary logic (treating mssings as unknown rather than false), SAS uses binary logic.

I think the the fourth parameter to IFC/IFN probably causes more confusion than it is worth.  Many people familiar with SAS will not expect it to be there, and folks reading the docs quickly will think that it will work as David expected.


New Contributor
Posts: 2

Re: Using the IFC and IFN functions

Thanks everyone for your replies! That was exactly what I needed to know, I definitely understand the IFC/IFN functions better now

Thanks again!

Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation