<?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: Substr of a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408941#M99881</link>
    <description>&lt;P&gt;Overcomplicating the code makes it harder for you to see the real problem:&amp;nbsp; 02 is a separate condition (which is always true), 03 is another separate condition (which is also always true).&amp;nbsp; Both of those are unrelated to the comparison to 01.&amp;nbsp; Since you turned on MLOGIC, you should see messages about that in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A suggested approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let ins = "%substr(&amp;amp;p_taxd_no, 7, 2)";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;ins="01" or &amp;amp;ins="02" or &amp;amp;ins="03" then %let ins=CHASE;&lt;/P&gt;
&lt;P&gt;%else if &amp;amp;ins="11" or &amp;amp;ins="12" or &amp;amp;ins="24" then %let ins=DISCOVER;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ins;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2017 23:25:55 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-10-30T23:25:55Z</dc:date>
    <item>
      <title>Substr of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408926#M99875</link>
      <description>&lt;P&gt;Hi I have&lt;/P&gt;
&lt;P&gt;p_taxd_no as&lt;/P&gt;
&lt;P&gt;Taxd_001&lt;/P&gt;
&lt;P&gt;Taxd_002&lt;/P&gt;
&lt;P&gt;Taxd_003&lt;/P&gt;
&lt;P&gt;Taxd_011&lt;/P&gt;
&lt;P&gt;Taxd_024&lt;/P&gt;
&lt;P&gt;Taxd_012&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Test1(p_taxd_no);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;options mprint mlogic symbolgen;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(qsubstr(&amp;amp;p_taxd_no,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; or &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; or 03 &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ins = CHASE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;ins;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(qsubstr(&amp;amp;p_taxd_no,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;11&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; or &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp; or 24 &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ins = DISCOVER;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;ins;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Test1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;test1&lt;/I&gt;&lt;/STRONG&gt;(Taxd_002);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But here both conditions are becoming true . So can u please let me know how to resolve so that only INS = CHASE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 22:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408926#M99875</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2017-10-30T22:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Substr of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408928#M99877</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 01 or 02  or 03 %then %do;
%let ins = CHASE;
%end;
%put &amp;amp;ins;
%else %do;
%let ins = DISCOVER;
%end;
 
%put &amp;amp;ins;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of using if then twice use else for second condition.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 22:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408928#M99877</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-10-30T22:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Substr of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408941#M99881</link>
      <description>&lt;P&gt;Overcomplicating the code makes it harder for you to see the real problem:&amp;nbsp; 02 is a separate condition (which is always true), 03 is another separate condition (which is also always true).&amp;nbsp; Both of those are unrelated to the comparison to 01.&amp;nbsp; Since you turned on MLOGIC, you should see messages about that in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A suggested approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let ins = "%substr(&amp;amp;p_taxd_no, 7, 2)";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;ins="01" or &amp;amp;ins="02" or &amp;amp;ins="03" then %let ins=CHASE;&lt;/P&gt;
&lt;P&gt;%else if &amp;amp;ins="11" or &amp;amp;ins="12" or &amp;amp;ins="24" then %let ins=DISCOVER;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ins;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 23:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408941#M99881</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-30T23:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Substr of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408942#M99882</link>
      <description>&lt;P&gt;You'll need to use the IN operator, and in this case you'll also need the MINOPERATOR option to make it work with macro variables. In your current code, SAS is effectively testing 02 = 02 or that 12=12. Since these are always true, that's why both conditions are becoming true.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Test1(p_taxd_no);
options mprint mlogic symbolgen minoperator;
%if %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) in ( 01 02 03) %then %do;
%let ins = CHASE;
%end;
%put &amp;amp;ins;
%if %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) in ( 11 12 24) %then %do;
%let ins = DISCOVER;
%end;
 
%put &amp;amp;ins;
%mend Test1;
%test1(Taxd_002);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 23:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/408942#M99882</guid>
      <dc:creator>bstarr</dc:creator>
      <dc:date>2017-10-30T23:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Substr of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/409003#M99900</link>
      <description>&lt;P&gt;This condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 01 or 02  or 03 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is semantically and syntactically equivalent to this condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (%sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 01) or (02) or (03) %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A numeric, non-zero/non-missing value is always considered as a boolean true.&lt;/P&gt;
&lt;P&gt;What you want is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if
  %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 01 or
  %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 02 or
  %sysfunc(qsubstr(&amp;amp;p_taxd_no,7,2)) = 03
%then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively, activate the minoperator system option and use IN as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174733"&gt;@bstarr&lt;/a&gt; suggested.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 06:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substr-of-a-macro/m-p/409003#M99900</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-31T06:42:05Z</dc:date>
    </item>
  </channel>
</rss>

