<?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 IN operator with %IF %THEN %ELSE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395886#M95552</link>
    <description>&lt;P&gt;Look at the MINDELIMITER system option or / MINDELIMITER= option on the %MACRO statement in the on-line documentation. You should find examples there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used INDEXW() function to do this and find it works well and avoids worrying&amp;nbsp;about MINDELIMITER.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %sysfunc(indexw(A B C,&amp;amp;param)) %THEN %DO;
        .........................
%END;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2017 12:13:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-09-14T12:13:57Z</dc:date>
    <item>
      <title>Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395877#M95547</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to use IN operator with %IF similar to what we do in data step IF THEN ELSE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for eample I need to use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro xxxxx(param= );&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%IF &amp;amp;param. IN (A,B,C) %THEN %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .........................&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%ELSE &lt;SPAN&gt;%IF &amp;amp;param. IN (E,F,G) %THEN %DO;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;....................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;%END;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%xxxxxx(param=A);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%xxxxxx(param=G);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 11:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395877#M95547</guid>
      <dc:creator>kingCobra</dc:creator>
      <dc:date>2017-09-14T11:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395878#M95548</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/35/591.html" target="_blank"&gt;http://support.sas.com/kb/35/591.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However there doesn't seem to be much reason to do it this way. &amp;nbsp;Your macro is just a complicated way of avoiding doing Base SAS. &amp;nbsp;Post some real example code and will describe further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 11:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395878#M95548</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-14T11:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395880#M95549</link>
      <description>&lt;P&gt;Yes, but it looks a little different. &amp;nbsp;At a minimum, parentheses should not be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read up on two options: &amp;nbsp;minoperator and mindelimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you set the MINDELIMITER option to |, you would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;param. in A|B|C %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are allowed to use a comma as the value of MINDELIMITER, but that's not a requirement. &amp;nbsp;Do not leave extra spaces on either side of your delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n0vc5y2nyi55dvn1agla9j658kwh.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n0vc5y2nyi55dvn1agla9j658kwh.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p0pbehl7wj5sl4n1ov1ortnehtba.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p0pbehl7wj5sl4n1ov1ortnehtba.htm&lt;/A&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>Thu, 14 Sep 2017 11:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395880#M95549</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-14T11:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395882#M95550</link>
      <description>&lt;P&gt;RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made this simplified to facilitate understanding. The main issue is if &amp;amp;param has certain values, I want to execute certain steps. I have several of such %IF %THEN %ELSE block of codes.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 11:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395882#M95550</guid>
      <dc:creator>kingCobra</dc:creator>
      <dc:date>2017-09-14T11:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395884#M95551</link>
      <description>&lt;P&gt;Thats why I say it depends on the other code I can't see. &amp;nbsp;There are two simple options:&lt;/P&gt;
&lt;P&gt;1) Have two macros, and call one or the other based on the data:&lt;/P&gt;
&lt;PRE&gt;%macro param_unit (param=,unit=);
...
%mend;

%macro param (param=);
...
%mend;

data want;
  set have;
  if param in ("A","B","C") then call execute(cats('%param_unit (param=',param,",unit=',unit,');'));
  else call execute(cats('%param (param=',param,');'));
run;&lt;/PRE&gt;
&lt;P&gt;Or you could od it in the datastep within the macro, or you could do it in datastep with no macro. &amp;nbsp;Probably several other options.&lt;/P&gt;
&lt;P&gt;Edit; Just to add, the point of macro is to create generic reusable code, hardcoding data requirements in it reduces both these.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 12:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395884#M95551</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-14T12:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using IN operator with %IF %THEN %ELSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395886#M95552</link>
      <description>&lt;P&gt;Look at the MINDELIMITER system option or / MINDELIMITER= option on the %MACRO statement in the on-line documentation. You should find examples there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used INDEXW() function to do this and find it works well and avoids worrying&amp;nbsp;about MINDELIMITER.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %sysfunc(indexw(A B C,&amp;amp;param)) %THEN %DO;
        .........................
%END;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 12:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-IN-operator-with-IF-THEN-ELSE/m-p/395886#M95552</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-14T12:13:57Z</dc:date>
    </item>
  </channel>
</rss>

