<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using the IFC and IFN functions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78696#M22669</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works in the following instance with numeric and character data, but I can't get it to work for with N=..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA Work.TestIfc;&lt;/P&gt;&lt;P&gt;attrib N length = 4&lt;/P&gt;&lt;P&gt;Value length = $ %length(missing);&lt;/P&gt;&lt;P&gt;do N = ., 0, 1, -1;&lt;/P&gt;&lt;P&gt;Value = ifc(N&lt;/P&gt;&lt;P&gt;,"true"&lt;/P&gt;&lt;P&gt;,"false"&lt;/P&gt;&lt;P&gt;,"missing"&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jul 2013 11:14:57 GMT</pubDate>
    <dc:creator>Scott_Mitchell</dc:creator>
    <dc:date>2013-07-15T11:14:57Z</dc:date>
    <item>
      <title>Using the IFC and IFN functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78695#M22668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having an issue with the IFC and IFN functions using SAS version 9.1.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on the SAS documentation, these functions can be used to return 3 different values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #575757;"&gt;The syntax is written as:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #575757;"&gt;IFC(logical-expression, value-returned-when-true, value-returned-when-false ,&amp;lt;value-returned-when-missing&amp;gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;DL&gt;&lt;DT&gt;&lt;STRONG&gt;value-returned-when-true&lt;/STRONG&gt; specifies a character expression that is returned when the value of logical-expression is true. &lt;/DT&gt;&lt;DT&gt;&lt;STRONG&gt;value-returned-when-false &lt;/STRONG&gt;specifies a character expression that is returned when the value of logical-expression is false. &lt;/DT&gt;&lt;DT&gt;&lt;STRONG&gt;value-returned-when-missing &lt;/STRONG&gt;specifies a character expression that is returned when the value of logical-expression is missing &lt;/DT&gt;&lt;/DL&gt;&lt;P&gt;Just as an example here is some code I have tried out.&lt;/P&gt;&lt;P&gt;I have created the class dataset:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data &lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;input &lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;id name $&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;9&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; 1 Henry&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; 2 Alice &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: #ffffc0; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; 3&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I create the class2 dataset, and use the IFC function to try assign 3 different values for a new variable&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data &lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;class2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New'; font-size: 10pt;"&gt;set &lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;answer=ifc(name=&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;'Henry'&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;'Yes'&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;'No'&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;'Missing'&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="line-height: 115%; color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; line-height: 115%; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;The created dataset looks like this:&lt;BR /&gt;&lt;IMG alt="class2.png" class="jive-image" src="https://communities.sas.com/legacyfs/online/3900_class2.png" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;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&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know what I am doing wrong? &lt;/P&gt;&lt;P&gt;Or if there is a problem with these functions? &lt;/P&gt;&lt;P&gt;Or has an example of how to correctly use these functions to return seperate values for true, false and missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that all makes sense! And ideas would be greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 10:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78695#M22668</guid>
      <dc:creator>davidhw</dc:creator>
      <dc:date>2013-07-15T10:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IFC and IFN functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78696#M22669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works in the following instance with numeric and character data, but I can't get it to work for with N=..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA Work.TestIfc;&lt;/P&gt;&lt;P&gt;attrib N length = 4&lt;/P&gt;&lt;P&gt;Value length = $ %length(missing);&lt;/P&gt;&lt;P&gt;do N = ., 0, 1, -1;&lt;/P&gt;&lt;P&gt;Value = ifc(N&lt;/P&gt;&lt;P&gt;,"true"&lt;/P&gt;&lt;P&gt;,"false"&lt;/P&gt;&lt;P&gt;,"missing"&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 11:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78696#M22669</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2013-07-15T11:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IFC and IFN functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78697#M22670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;David,&lt;/P&gt;&lt;P&gt;The confusion lies in what IFC examines to determine true / false / missing.&amp;nbsp; It is NOT looking at the value of NAME.&amp;nbsp; Rather, it is looking at the truth / falsity of the first argument (name='Henry').&amp;nbsp; When NAME is Henry, the comparison returns a 1 which SAS interprets as true.&amp;nbsp; When NAME is anything else (including a blank), the comparison returns a 0 which SAS interprets as false.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Scott's example illustrates, the first argument would have to return a missing value in order for the fourth argument to kick in.&amp;nbsp; But a comparison as the first argument will always return 1 or 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 13:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78697#M22670</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-07-15T13:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IFC and IFN functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78698#M22671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agree with Astounding's nice explanation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Curious if folks see much benefit to SAS having implemented IFC and IFN with such optional trinary logic? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just about everywhere else I can think of in SAS, it uses binary logic.&amp;nbsp; Even in PROC SQL, where many SQL implementations use trinary logic (treating mssings as unknown rather than false), SAS uses binary logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the the fourth parameter to IFC/IFN probably causes more confusion than it is worth.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 17:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78698#M22671</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-07-15T17:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using the IFC and IFN functions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78699#M22672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks everyone for your replies! That was exactly what I needed to know, I definitely understand the IFC/IFN functions better now&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jul 2013 07:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-the-IFC-and-IFN-functions/m-p/78699#M22672</guid>
      <dc:creator>davidhw</dc:creator>
      <dc:date>2013-07-16T07:03:46Z</dc:date>
    </item>
  </channel>
</rss>

