<?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: if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278067#M55919</link>
    <description>&lt;P&gt;Can A/B/C variables have any value at all, if not there may be other options.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An array is probably easier and faster than a macro, especially if the values aren't 1/2/3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array var_list(*) a b c;
flag=0;
do i=1,2,3;
	if whichn(i, of var_list(*))&amp;gt;0 then do;
		flag=123;
		leave;
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&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>Fri, 17 Jun 2016 01:29:19 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-17T01:29:19Z</dc:date>
    <item>
      <title>if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278053#M55911</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want&amp;nbsp;simplify a complex if statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;/P&gt;
&lt;P&gt;set had;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if a in(1, 2, 3) or&amp;nbsp; b in (1,2,3)&amp;nbsp; or c in (1,2,3) then x=123;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is can I simplify the if statement like this?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data need;&lt;/P&gt;
&lt;P&gt;set had;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if&amp;nbsp;(a or b or c) in (1,2,3)&amp;nbsp;then x=123;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 23:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278053#M55911</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2016-06-16T23:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278061#M55916</link>
      <description>&lt;P&gt;No.That is not right.&lt;/P&gt;
&lt;P&gt;However, if you are using SAS/IML , there is a function ELEMENT() can do that.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 00:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278061#M55916</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-17T00:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278064#M55917</link>
      <description>&lt;P&gt;No you can't do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a long list of value, you can store them once only:&lt;/P&gt;
&lt;P&gt;%let list_values=1 2 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if a in(&amp;amp;list_values) or&amp;nbsp; b in&amp;nbsp;(&amp;amp;list_values) or c in (&amp;amp;list_values) then x=123;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a long list of variables you can use a macro loop to generate the statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro loop;&lt;/P&gt;
&lt;P&gt;%local&amp;nbsp;i&amp;nbsp;list_values list_variables;&lt;/P&gt;
&lt;P&gt;%let list_values=1 2 3;&lt;/P&gt;
&lt;P&gt;%let list_variables= a b c;&lt;/P&gt;
&lt;P&gt;if 0&lt;/P&gt;
&lt;P&gt;%do i=1 %to 3;&lt;/P&gt;
&lt;P&gt;or %scan(&amp;amp;list_variables, &amp;amp;i)&amp;nbsp;in (&amp;amp;list_values)&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;then x=123;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%loop;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 01:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278064#M55917</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-17T01:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278067#M55919</link>
      <description>&lt;P&gt;Can A/B/C variables have any value at all, if not there may be other options.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An array is probably easier and faster than a macro, especially if the values aren't 1/2/3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array var_list(*) a b c;
flag=0;
do i=1,2,3;
	if whichn(i, of var_list(*))&amp;gt;0 then do;
		flag=123;
		leave;
	end;
end;
run;&lt;/CODE&gt;&lt;/PRE&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>Fri, 17 Jun 2016 01:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278067#M55919</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-17T01:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278139#M55937</link>
      <description>&lt;P&gt;This example concatenates the three values, then strips out all occurences of 1,2,3, and thus any length &amp;gt; 0 indicates a character not in the list 1,2,3.&lt;/P&gt;
&lt;PRE&gt;data want;
  a=1; b=3; c=3; 
  if lengthn(compress(cats(a,b,c),"123"))=0 then x=123;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 09:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278139#M55937</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-17T09:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278145#M55938</link>
      <description>&lt;P&gt;That assumes single digit values?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 10:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278145#M55938</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-17T10:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278160#M55945</link>
      <description>&lt;P&gt;Yes, thats all he posted in the OP. &amp;nbsp;It could be that b=12 would pass that logic check, but be inaccurate as &amp;gt; 3, but he hasn't mentioned that. &amp;nbsp;If it is the case, then use catx() with a delimiter, and remove delimter+digit.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2016 11:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278160#M55945</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-17T11:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278162#M55946</link>
      <description>any value. (1,2,3) just an example, maybe there are more characters such as ('abc','qwe',.....more)</description>
      <pubDate>Fri, 17 Jun 2016 11:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278162#M55946</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2016-06-17T11:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278167#M55947</link>
      <description>&lt;P&gt;In which case then no. &amp;nbsp;If there is no logical reason to arrive at a formula then one wont exist. &amp;nbsp;As mentioned above arrays are probably your best bet, i.e.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array tmp &amp;lt;list of variables&amp;gt;;
  do over tmp;
    if tmp in (&amp;lt;set of values&amp;gt;) then result_value=&amp;lt;result&amp;gt;;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 12:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/278167#M55947</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-17T12:19:31Z</dc:date>
    </item>
  </channel>
</rss>

