<?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: IFN and IFC not working on missing character variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/864178#M341295</link>
    <description>&lt;P&gt;Yes, I understand that. I also agree that using informants or other options such as using select when or if else are simple and easily understandable. Thank you for&amp;nbsp; your suggestion.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 23:22:03 GMT</pubDate>
    <dc:creator>nbav001</dc:creator>
    <dc:date>2023-03-14T23:22:03Z</dc:date>
    <item>
      <title>IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863731#M341155</link>
      <description>&lt;P&gt;can someone please help me with this???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example codes&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input x $1;&lt;BR /&gt;z=ifc(x='M','zero','one','missing');&lt;BR /&gt;datalines;&lt;BR /&gt;M&lt;BR /&gt;F&lt;BR /&gt;&lt;BR /&gt;M&lt;BR /&gt;F&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test1;&lt;BR /&gt;input x $1;&lt;BR /&gt;z=ifn(x='M',0,1,.);&lt;BR /&gt;datalines;&lt;BR /&gt;M&lt;BR /&gt;F&lt;BR /&gt;&lt;BR /&gt;M&lt;BR /&gt;F&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=test;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=test1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nbav001_0-1678676092953.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81417i3DDC6A54CA181AF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nbav001_0-1678676092953.png" alt="nbav001_0-1678676092953.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 02:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863731#M341155</guid>
      <dc:creator>nbav001</dc:creator>
      <dc:date>2023-03-13T02:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863734#M341156</link>
      <description>&lt;P&gt;SAS does not do TRI-LEVEL logic. SAS only does BOOLEAN logic.&amp;nbsp; The value of X is either 'M' or it isn't. There is no third option.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to treat X=' ' as different than other non 'M' values then code it that way. Also why bother using IFC() or IFN() when you can use normal IF/THEN statements?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x $1.;
  length z $7 ;
  if x='M' then z='zero';
  else if missing(x) then z='missing';
  else z='one';
datalines;
M
F

M
F
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1678676469272.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81418iC667D4BA0CF23920/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1678676469272.png" alt="Tom_0-1678676469272.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 03:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863734#M341156</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-13T03:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863737#M341159</link>
      <description>&lt;P&gt;Reference1:&amp;nbsp;&lt;A href="https://www.lexjansen.com/wuss/2012/28.pdf" target="_blank"&gt;https://www.lexjansen.com/wuss/2012/28.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Reference2:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Reference3:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;According to the above documentation there is a 4th optional argument that can is used for IFN and IFC for missing values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I my case it is not working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 03:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863737#M341159</guid>
      <dc:creator>nbav001</dc:creator>
      <dc:date>2023-03-13T03:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863741#M341160</link>
      <description>&lt;P&gt;You are misinterpreting the documentation. The logical expression "x='M'"&amp;nbsp; can only be true or false, never missing. However if you do a calculation that produces a missing value then the 4th parameter applies:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  age = .;
  result = ifc (age * 10, 'Age times 10','Age not times 10','blank');
  put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 04:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863741#M341160</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-03-13T04:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863743#M341161</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440700"&gt;@nbav001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Reference1:&amp;nbsp;&lt;A href="https://www.lexjansen.com/wuss/2012/28.pdf" target="_blank" rel="noopener"&gt;https://www.lexjansen.com/wuss/2012/28.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Reference2:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Reference3:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l3n5z2h31h7wn1fmnqd33ibhap.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;According to the above documentation there is a 4th optional argument that can is used for IFN and IFC for missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I my case it is not working.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So the documentation you referenced is confusing because of the use of "logical-expression" as the name of the first argument.&amp;nbsp; SAS does not do tri-level logic so a test like A=B or X&amp;lt;Y can only ever evaluate to 1 (TRUE) or 0 (FALSE).&amp;nbsp; So if you actually code a boolean expression in that argument it will never have a missing value.&amp;nbsp; The only way to pass a missing value is to pass a value or an arithmetic expression.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 04:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863743#M341161</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-13T04:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863762#M341171</link>
      <description>&lt;P&gt;It might help to describe exactly what you are attempting to do instead of showing code that doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the object is to display a different value than that currently assigned to variable the basic tool might be a format. If you want to create a numeric value from text then an informat with input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value $mf
'M'='Zero'
'F'='One'
' '='Missing'
;
invalue mf2num
'M'=0
'F'=1
' '=.
;

data test;
input x $1.;
length z $ 8.;
z= put(x,mf.);
y= input(x,mf2num.);
datalines;
M
F

M
F
;&lt;/PRE&gt;
&lt;P&gt;With a Format to display existing values then you don't even need to create a new variable, just us Format X $mf.; where you want to see the text.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 11:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863762#M341171</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-13T11:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863771#M341175</link>
      <description>&lt;P&gt;What the IFC function does: evaluates an expression. If the expression evaluates to a number that is logical TRUE (in SAS, that is any number which is not zero or missing), it returns the second parameter, if the expression returns a zero, the function returns the third parmeter, and if the expression is missing, it will return the fourth parameter. If there is no fourth parameter, the function will return the third parameter for missing values also.&lt;/P&gt;
&lt;P&gt;e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;67   data _null_;
68     input x;
69     a=ifc(x,'a','b');
70     b=ifc(x,'a','b','c');
71     put x= a= b=;
72   cards;

x=. a=b b=c
x=0 a=b b=b
x=1 a=a b=a
x=-232352 a=a b=a
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;remarked, you may as well use normal IF..THEN..ELSE logic. It may be a bit more typing, but it is easier to read. And if you use IFC or IFN with more complicated output parameters, you should be aware that all the possible outputs will be calculated, which may require more CPU time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this last fact is also why IFC/IFN are often used with LAG and DIFF expressions. For instance this will probably not work as intended:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(a) then
  a=lag(a);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the LAG function will only store a value when A is missing. But this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a=ifc(missing(a),lag(a),a);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will work because the LAG function will be called every time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 12:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863771#M341175</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-13T12:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863920#M341203</link>
      <description>&lt;P&gt;Thank you everyone for your replies and suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following code and it worked for me.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nbav001_0-1678754818788.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81490iFCE9FDB6A10DD27D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nbav001_0-1678754818788.png" alt="nbav001_0-1678754818788.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 00:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/863920#M341203</guid>
      <dc:creator>nbav001</dc:creator>
      <dc:date>2023-03-14T00:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/864083#M341263</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440700"&gt;@nbav001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you everyone for your replies and suggestions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following code and it worked for me.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nbav001_0-1678754818788.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81490iFCE9FDB6A10DD27D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nbav001_0-1678754818788.png" alt="nbav001_0-1678754818788.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think that you might also want to consider a case where you have code values A B C D E F and G that are supposed to become 0, 1, 2, 3, 4, 5, 6 and 7 respectively with missing if the code is not present. Write that out with IFN and IFC. I suspect you will find out why I suggested the Informat approach.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/864083#M341263</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-14T15:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: IFN and IFC not working on missing character variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/864178#M341295</link>
      <description>&lt;P&gt;Yes, I understand that. I also agree that using informants or other options such as using select when or if else are simple and easily understandable. Thank you for&amp;nbsp; your suggestion.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 23:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IFN-and-IFC-not-working-on-missing-character-variables/m-p/864178#M341295</guid>
      <dc:creator>nbav001</dc:creator>
      <dc:date>2023-03-14T23:22:03Z</dc:date>
    </item>
  </channel>
</rss>

