<?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: ifc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367531#M87515</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like nested ifc() functions beacuse they are easily the most legible, if a bit wasteful; One knows exactly what the code does just by glancing at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ;
  A1=ifc(B&amp;lt;10     , 'A'
    ,ifc(B&amp;lt;20     , 'B'
    ,ifc(B&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B&amp;lt;20     , 'D'
    ,ifc(B&amp;lt;20     , 'E'
                  , 'F' )))));
  A2=ifc(B1&amp;lt;10     , 'A'
    ,ifc(B1&amp;lt;20     , 'B'
    ,ifc(B1&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B1&amp;lt;20     , 'D'
    ,ifc(B1&amp;lt;20     , 'E'
                   , 'F' )))));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if only SAS didn't try to resolve all arguments all the time, and instead&amp;nbsp;treated this function differently to other functions, we could also do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ;
  A=0;
  B=ifc(A&amp;gt;0, log(A), .);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2017 22:17:39 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-06-15T22:17:39Z</dc:date>
    <item>
      <title>ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367487#M87490</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In below program, I am trying to get same output using IFC alternative. Seems like I am missing something.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input x;
	cards;
1
2
;

data test1;
	set test;

	if x = 1 then
		a = 'A';
	else if x = 2 then
		a = 'B';
run;

data test2;
	set test;
	a=ifc(x=1,'A', ' ');
	a=ifc(x=2,'B', ' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 20:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367487#M87490</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-06-15T20:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367490#M87491</link>
      <description>&lt;P&gt;When the first observation executes in data set test2, x=1 and&amp;nbsp;a gets assigned the value of A, it then moves on to the second command and still x=1 which causes a to get assigned a missing value.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 20:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367490#M87491</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-15T20:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367491#M87492</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Thank you for the explanation. How to get the desired output using IFC if possible?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 20:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367491#M87492</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-06-15T20:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367494#M87493</link>
      <description>&lt;P&gt;Personally, I wouldn't even&amp;nbsp;try to fit this example into an IFC (or several IFC) commands, but I'm sure someone will come along with a brilliant solution.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 20:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367494#M87493</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-15T20:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367497#M87494</link>
      <description>&lt;P&gt;The answer to your question depends on the possible value of x. &amp;nbsp;If you know that x only takes on two values (1 and 2), then you can use&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;a&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ifc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;x&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'A'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'B'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;If x can be 1, 2, or 'other', then you could use&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;a&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ifc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;x&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'A'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; ifc(x=2,'B',&lt;SPAN class="token string"&gt;' ')&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;You can also use arrays, like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
array AVals[3] $ _temporary_ ('A', 'B', ' ');
set test;
a = AVals[x];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have many valid values, I suggest you look at &lt;A href="http://blogs.sas.com/content/iml/2016/06/20/select-when-sas-data-step.html" target="_self"&gt;the SELECT-WHEN statement.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 20:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367497#M87494</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-15T20:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367531#M87515</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like nested ifc() functions beacuse they are easily the most legible, if a bit wasteful; One knows exactly what the code does just by glancing at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ;
  A1=ifc(B&amp;lt;10     , 'A'
    ,ifc(B&amp;lt;20     , 'B'
    ,ifc(B&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B&amp;lt;20     , 'D'
    ,ifc(B&amp;lt;20     , 'E'
                  , 'F' )))));
  A2=ifc(B1&amp;lt;10     , 'A'
    ,ifc(B1&amp;lt;20     , 'B'
    ,ifc(B1&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B1&amp;lt;20     , 'D'
    ,ifc(B1&amp;lt;20     , 'E'
                   , 'F' )))));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if only SAS didn't try to resolve all arguments all the time, and instead&amp;nbsp;treated this function differently to other functions, we could also do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ;
  A=0;
  B=ifc(A&amp;gt;0, log(A), .);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 22:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367531#M87515</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-06-15T22:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367534#M87517</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;already answered your question. However, in this case, I wouldn't use the ifc function. I'd use:&lt;/P&gt;
&lt;PRE&gt;data test1;
  set test;
  a=byte(x+64);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 22:33:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367534#M87517</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-15T22:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367547#M87525</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like nested ifc() functions beacuse they are easily the most legible, if a bit wasteful; One knows exactly what the code does just by glancing at it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ;
  A1=ifc(B&amp;lt;10     , 'A'
    ,ifc(B&amp;lt;20     , 'B'
    ,ifc(B&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B&amp;lt;20     , 'D'
    ,ifc(B&amp;lt;20     , 'E'
                  , 'F' )))));
  A2=ifc(B1&amp;lt;10     , 'A'
    ,ifc(B1&amp;lt;20     , 'B'
    ,ifc(B1&amp;lt;20 &amp;amp; C , 'C'
    ,ifc(B1&amp;lt;20     , 'D'
    ,ifc(B1&amp;lt;20     , 'E'
                   , 'F' )))));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Legibility is in the eye of the beholder. I consider this illegible.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 23:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367547#M87525</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-15T23:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: ifc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367595#M87552</link>
      <description>&lt;P&gt;&amp;gt;Legibility is in the eye of the beholder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indeed, so it seems.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2017 03:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ifc/m-p/367595#M87552</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-06-16T03:01:58Z</dc:date>
    </item>
  </channel>
</rss>

