<?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: %qsubstr in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364372#M86424</link>
    <description>&lt;P&gt;After resolution of the macro function, you get this data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  a = 12&amp;amp;3;
  put a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp; is a mnemonic for the boolean "and" operator, so the SAS interpreter sees the 12 and the 3 as boolean values; since both are non-zero, this resolves to the boolean expression "true and true", so the result is "true", which is represented in SAS by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a to be the string "12&amp;amp;3", you would have needed to write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  a = "%qsubstr(12&amp;amp;34,1,4)";
  put a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Jun 2017 20:51:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-06-05T20:51:41Z</dc:date>
    <item>
      <title>%qsubstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364366#M86421</link>
      <description>&lt;P&gt;I wonder why this does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	a = %qsubstr(12&amp;amp;34,1,4);
	put a;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;expected ouput : 12&amp;amp;3&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364366#M86421</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-06-05T20:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: %qsubstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364371#M86423</link>
      <description>&lt;P&gt;Macro functions are not part of a DATA step.&amp;nbsp; You might as well have coded:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt; a &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;34&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&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 number"&gt;4&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800000"&gt;Note that Kurt is right about what you get when you do use %QSUBSTR ... 12&amp;amp;3 (not what I posted above).&amp;nbsp; Now that will get resolved by as DATA step into the number 1.&amp;nbsp; 12 is true, 3 is true, so 12 &amp;amp; 3 is true and gets resolved to 1.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;In a DATA step,&amp;nbsp; you might simply use:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_;&lt;BR /&gt; a &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; substr('&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;34'&lt;/SPAN&gt;,&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;,&lt;SPAN class="token number"&gt;4&lt;/SPAN&gt;);&lt;BR /&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt; a;&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Single quotes always turn off macro processing, whether in a DATA step or in macro language statements.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364371#M86423</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-05T20:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: %qsubstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364372#M86424</link>
      <description>&lt;P&gt;After resolution of the macro function, you get this data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  a = 12&amp;amp;3;
  put a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp; is a mnemonic for the boolean "and" operator, so the SAS interpreter sees the 12 and the 3 as boolean values; since both are non-zero, this resolves to the boolean expression "true and true", so the result is "true", which is represented in SAS by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted a to be the string "12&amp;amp;3", you would have needed to write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  a = "%qsubstr(12&amp;amp;34,1,4)";
  put a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Jun 2017 20:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364372#M86424</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-05T20:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: %qsubstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364380#M86429</link>
      <description>&lt;P&gt;Thank you both for great explanation.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 21:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/qsubstr/m-p/364380#M86429</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-06-05T21:16:17Z</dc:date>
    </item>
  </channel>
</rss>

