<?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 SAS Quoting Function %STR in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318744#M69876</link>
    <description>&lt;P&gt;Hello, I am learning&amp;nbsp;macro quoting functions and I got some questions. Hope some of you expert can help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the code I ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;options mlogic mprint;&lt;BR /&gt;%macro translate (var);&lt;BR /&gt;%if &amp;amp;var = %str(EQ) %then %put The result is correct;&lt;BR /&gt;%else %put The result is incorrect;&lt;BR /&gt;%mend;&lt;BR /&gt;%translate(EQ)&lt;/PRE&gt;&lt;P&gt;The mlogic shows the condition is false :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;var = EQ is FALSE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is incorrect&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is incorrect&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;I'm assuming this is because the &amp;amp;var needs to masked as well in the %IF condition. Because I want to mask the resolved value, I used the %bquote quoting function:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro translate (var);
%if %bquote(&amp;amp;var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;It works which is great:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition %bquote(&amp;amp;var) = EQ is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;And now, I'm just doing a quick experiment and I used the %str instead of the %bquote function:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro translate (var);
%if %str(&amp;amp;var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;It also works.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;var = EQ is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;So my question is, why does the %str works when I use it on the &amp;amp;var. From what I understand, the %str masks the value in compile time where the &amp;amp;var value is not resolved. So when it comes the execution time, the resolved value (which is EQ) should not be masked and this should cause %IF condition to fail.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Could anyone explain why the %str function works in this example?&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2016 03:17:48 GMT</pubDate>
    <dc:creator>kisumsam</dc:creator>
    <dc:date>2016-12-14T03:17:48Z</dc:date>
    <item>
      <title>SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318744#M69876</link>
      <description>&lt;P&gt;Hello, I am learning&amp;nbsp;macro quoting functions and I got some questions. Hope some of you expert can help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the code I ran:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;options mlogic mprint;&lt;BR /&gt;%macro translate (var);&lt;BR /&gt;%if &amp;amp;var = %str(EQ) %then %put The result is correct;&lt;BR /&gt;%else %put The result is incorrect;&lt;BR /&gt;%mend;&lt;BR /&gt;%translate(EQ)&lt;/PRE&gt;&lt;P&gt;The mlogic shows the condition is false :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;var = EQ is FALSE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is incorrect&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is incorrect&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;I'm assuming this is because the &amp;amp;var needs to masked as well in the %IF condition. Because I want to mask the resolved value, I used the %bquote quoting function:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro translate (var);
%if %bquote(&amp;amp;var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;It works which is great:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition %bquote(&amp;amp;var) = EQ is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;And now, I'm just doing a quick experiment and I used the %str instead of the %bquote function:&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro translate (var);
%if %str(&amp;amp;var) = %str(EQ) %then %put The result is correct;
%else %put The result is incorrect;
%mend;
%translate(EQ)&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;It also works.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Beginning execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Parameter VAR has value EQ&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;var = EQ is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): %PUT The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;The result is correct&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(TRANSLATE): Ending execution.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;So my question is, why does the %str works when I use it on the &amp;amp;var. From what I understand, the %str masks the value in compile time where the &amp;amp;var value is not resolved. So when it comes the execution time, the resolved value (which is EQ) should not be masked and this should cause %IF condition to fail.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;Could anyone explain why the %str function works in this example?&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 03:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318744#M69876</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-14T03:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318752#M69881</link>
      <description>&lt;P&gt;options mlogic mprint;&lt;BR /&gt;%macro translate (var);&lt;BR /&gt;%if &lt;FONT color="#FF0000"&gt;%bquote(&amp;amp;var)&lt;/FONT&gt; = %str(EQ) %then %put The result is correct;&lt;BR /&gt;%else %put The result is incorrect;&lt;BR /&gt;%mend;&lt;BR /&gt;%translate(EQ)&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 04:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318752#M69881</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-14T04:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318753#M69882</link>
      <description>&lt;P&gt;%str mask value in complie stage, %bquote mask value in execute stage.&lt;/P&gt;
&lt;P&gt;compile stage is BEFORE execute stage.&lt;/P&gt;
&lt;P&gt;Therefore BOTH worked.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 04:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318753#M69882</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-14T04:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318927#M69936</link>
      <description>&lt;P&gt;Thanks for your response KSharp. I'm not sure if I followed tho. I thought the %str masks the value before it is resolved and it won't mask the resolved value. That's why we needed the bquote.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example that I read from another Sesug article:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%Let A = X,X ;&lt;BR /&gt;%Let B = Y%Str(&amp;amp;A)Y ;&lt;BR /&gt;%Put %Substr( &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%str&lt;/STRONG&gt;&lt;/FONT&gt;(&amp;amp;B) , 4 , 1 );&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the third line, I'm masking &amp;amp;B with the %str function and it gives me error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;56 %Let A = X,X ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;57 %Let B = Y%Str(&amp;amp;A)Y ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;58 %Put %Substr( %str(&amp;amp;B) , 4 , 1 );&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Macro function %SUBSTR has too many arguments.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;I'm assuming this is because %str doesn't mask the resolved value which is YX,XY. The extra comma makes it an error in the %substr function.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;Now, if I switch it to bquote which I believe masks the resolved value, it works:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let A = X,X ;
%Let B = Y%Str(&amp;amp;A)Y ;
%Put %Substr( &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%bquote&lt;/STRONG&gt;&lt;/FONT&gt;(&amp;amp;B) , 4 , 1 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;Can I assume&amp;nbsp;the %str doesn't mask the resolved value? If yes, the previous example:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;%str(&amp;amp;var) shouldn't work because it doesn't mask the resolved value EQ.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#000000"&gt;Can someone clarify on this? I'm confused...&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 13:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318927#M69936</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-14T13:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318950#M69941</link>
      <description>&lt;P&gt;See this paper.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi28/011-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/011-28.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 15:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318950#M69941</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-12-14T15:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318983#M69955</link>
      <description>&lt;P&gt;From the documentation, %str masks&lt;/P&gt;
&lt;PRE&gt;&lt;A name="a002560381" target="_blank"&gt;&lt;/A&gt;+ - * / &amp;lt; &amp;gt; = ¬ ^ ~ ; ,  # blank
AND OR NOT EQ NE LE LT GE GT IN&lt;/PRE&gt;
&lt;P&gt;Note that you are using it with &amp;amp; so %str may not do what you want.&lt;/P&gt;
&lt;P&gt;%NSTR does the same as %str but adds: &amp;amp; %&lt;/P&gt;
&lt;P&gt;So perhaps you want %NSTR in this case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 16:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318983#M69955</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-14T16:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Quoting Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318997#M69960</link>
      <description>&lt;P&gt;Thanks so much! I know this topic is complex and this paper explains the concept very well. Will probably have to re-read it a few times to fully understand macro quoting.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 17:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Quoting-Function-STR/m-p/318997#M69960</guid>
      <dc:creator>kisumsam</dc:creator>
      <dc:date>2016-12-14T17:14:05Z</dc:date>
    </item>
  </channel>
</rss>

