<?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 Macro - %IF/%INDEX logic not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-INDEX-logic-not-working/m-p/578258#M163965</link>
    <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please suggest why the macro 'want' is not executing. I need to output data set 'two'.&amp;nbsp; Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $10.;
datalines;
aaaa+bbbbb
cccc+ddddd
;

%global treat1 treat2;
proc sql noprint;
    select strip(put(count (distinct a), best.)) into: cnt from one;
 select distinct a into :treat1 -:treat&amp;amp;cnt. from one
 order by a;
quit;

%put &amp;amp;treat1.;

%macro want;
%if %index(&amp;amp;treat1.,'+')&amp;gt;0 %then %do;
data two;
set one;
run;
%end;
%mend;
%want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data set&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2019 04:14:18 GMT</pubDate>
    <dc:creator>knveraraju91</dc:creator>
    <dc:date>2019-08-01T04:14:18Z</dc:date>
    <item>
      <title>Macro - %IF/%INDEX logic not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-INDEX-logic-not-working/m-p/578258#M163965</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please suggest why the macro 'want' is not executing. I need to output data set 'two'.&amp;nbsp; Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $10.;
datalines;
aaaa+bbbbb
cccc+ddddd
;

%global treat1 treat2;
proc sql noprint;
    select strip(put(count (distinct a), best.)) into: cnt from one;
 select distinct a into :treat1 -:treat&amp;amp;cnt. from one
 order by a;
quit;

%put &amp;amp;treat1.;

%macro want;
%if %index(&amp;amp;treat1.,'+')&amp;gt;0 %then %do;
data two;
set one;
run;
%end;
%mend;
%want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data set&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 04:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-INDEX-logic-not-working/m-p/578258#M163965</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2019-08-01T04:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: need help in my code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-IF-INDEX-logic-not-working/m-p/578263#M163967</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Get rid of the single quotes around the +, i.e. instead of '+', code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %index (&amp;amp;treat1, +) &amp;gt; 0 %then %do ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro language is character-based and understands tokens literally - i.e., if you code '+', that is what the %index function will be looking for, replete with the quotes; and there're no quotes in your &amp;amp;treat1 value. And, while at that, get rid of the superfluous period after &amp;amp;treat1 - as Ian Whitlock repeatedly stated, it's a bad habit to code a period after a dereferenced macro variable "just in case" without the exact reason why it must be used - i.e. to avoid macro resolution ambiguity or include a period in the macro-generated text. It leads to nothing but confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 04:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-IF-INDEX-logic-not-working/m-p/578263#M163967</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-01T04:06:44Z</dc:date>
    </item>
  </channel>
</rss>

