<?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: Why does %bquote work in this code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642989#M191864</link>
    <description>&lt;P&gt;Why would %BQUOTE() not have any effect just because you used it in the middle of a %LET statement?&lt;/P&gt;</description>
    <pubDate>Sun, 26 Apr 2020 03:39:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-04-26T03:39:02Z</dc:date>
    <item>
      <title>Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642988#M191863</link>
      <description>&lt;P&gt;I am trying to understand why the Macro quoting function &lt;STRONG&gt;%bquote&amp;nbsp;&lt;/STRONG&gt;works in the simple %LET&amp;nbsp; statement below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code below&amp;nbsp; I&amp;nbsp; understand why the First %LET&amp;nbsp; does not work and the Second %LET works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why does the Third %LET also work even though &lt;STRONG&gt;%bquote&lt;/STRONG&gt; has no&amp;nbsp; Macro quoting effect during the compilation of %LET&amp;nbsp; statement?&amp;nbsp; I would have expected this to end up with an error similar to error seen from the execution of&amp;nbsp; First&amp;nbsp; %LET below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any thoughts&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13683"&gt;@ArtC&lt;/a&gt;&amp;nbsp;&amp;nbsp; and others?&amp;nbsp; Code executed on SAS Studio which comes with SAS OnDemand for Academics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Error&amp;nbsp; from First %LET statement in below Code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;DIV id="sasLogError1_1587870994205" class="sasError"&gt;
&lt;DIV class="sasSource"&gt;&lt;EM&gt;%Let x1= Example;Sample;;&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_______&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&lt;EM&gt;180&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1587870994205" class="sasError"&gt;&lt;EM&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&lt;U&gt;&lt;STRONG&gt;Code :&lt;/STRONG&gt;&lt;/U&gt;&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* This obviously will not work*/
%Let x1= Example;Sample;;

%Put &amp;amp;=x1;

/* This will work*/
%Let x2= %str(Example;Sample;);

%Put &amp;amp;=x2;


/* This too will work. Not sure why*/
%Let x3= %bquote(Example;Sample;);


%Put &amp;amp;=x3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 05:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642988#M191863</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2020-04-26T05:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642989#M191864</link>
      <description>&lt;P&gt;Why would %BQUOTE() not have any effect just because you used it in the middle of a %LET statement?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 03:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642989#M191864</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-26T03:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642990#M191865</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &amp;nbsp;I meant to say when the third&amp;nbsp; %LET statement compiles, the semicolon after the word &lt;STRONG&gt;Example&amp;nbsp;&lt;/STRONG&gt;will not be masked by the %bquote and therefore the macro processor should regard this semicolon as terminating the %LET&amp;nbsp; statement similar to what happens when the First %LET compiles and executes. An Error is what i was expecting. Am i wrong?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 03:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642990#M191865</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2020-04-26T03:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642991#M191866</link>
      <description>&lt;P&gt;%BQUOTE() definitely quotes semi-colons.&amp;nbsp; Wouldn't be much of a macro quoting function if it didn't.&lt;/P&gt;
&lt;P&gt;Try it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=%bquote(;);

%let y=a&amp;amp;x.b;

%put &amp;amp;=y;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 03:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642991#M191866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-26T03:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642992#M191867</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &amp;nbsp;Sure Tom.&amp;nbsp; &amp;nbsp;But&amp;nbsp; what i don't understand is why this quoting is happening.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According the&amp;nbsp; documentation :&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0frhtfqvguv78n1owh5wfeopdrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0frhtfqvguv78n1owh5wfeopdrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;%BQUOTE and %NRBQUOTE mask values &lt;STRONG&gt;during execution&lt;/STRONG&gt; of a macro or a macro language statement in open code.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As per the statement above, &lt;STRONG&gt;%bquote&lt;/STRONG&gt; will not mask the semicolon after the word &lt;STRONG&gt;Example&lt;/STRONG&gt; while the third %LET statement compiles, and this semicolon will thus end the&amp;nbsp; %LET&amp;nbsp; statement and when it executes the value assigned to macro variable x3&amp;nbsp; should only be &lt;STRONG&gt;Example &lt;/STRONG&gt;. The orphan token&amp;nbsp;&lt;STRONG&gt;Sample&amp;nbsp;&lt;/STRONG&gt;should result in an Error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I wrong in understanding the above?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 04:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642992#M191867</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2020-04-26T04:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642999#M191869</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14002"&gt;@pchegoor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;According the&amp;nbsp; documentation :&amp;nbsp;&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0frhtfqvguv78n1owh5wfeopdrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0frhtfqvguv78n1owh5wfeopdrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;%BQUOTE and %NRBQUOTE mask values &lt;STRONG&gt;during execution&lt;/STRONG&gt; of a macro or a macro language statement in open code.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As per the statement above, &lt;STRONG&gt;%bquote&lt;/STRONG&gt; will not mask the semicolon after the word &lt;STRONG&gt;Example&lt;/STRONG&gt; while the third %LET statement compiles,...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My understanding is that "&lt;EM&gt;a macro language statement in open code&lt;/EM&gt;" -- such as your %LET statement -- is immediately executed upon submission. (After all, the assigned value can be retrieved in the next statement.) Hence, "as per the statement above," &lt;FONT face="courier new,courier"&gt;%bquote&lt;/FONT&gt; &lt;EM&gt;will&lt;/EM&gt; mask the semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, in a macro the same %LET statement would not work because the (first) semicolon would be processed &lt;EM&gt;during compilation&lt;/EM&gt; of the macro. It would mark the end of the %LET statement (as &lt;FONT face="courier new,courier"&gt;%bquote&lt;/FONT&gt; does not quote it during compilation) and during macro execution it would not even be considered part of the argument of &lt;FONT face="courier new,courier"&gt;%bquote&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 09:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/642999#M191869</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-26T09:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643017#M191870</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14002"&gt;@pchegoor&lt;/a&gt;&amp;nbsp;, I can't give you a good explanation for why %BQUOTE works like %STR() in open code.&amp;nbsp; I know that it does, because I've seen people do it, and it works, but it always feels wrong to me when I see it, and I don't use %BQUOTE that way myself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The difference between %STR and %BQUOTE is clear when they are used inside of a macro definition.&amp;nbsp; As the docs says, %STR() masks characters during macro compile time, and %BQUOTE masks characters during macro execution time.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo1() ;
  %*This does NOT work cuz %BQUOTE masks at macro execution time ;
  %Let x1= %bquote(Example;Sample;);
  %put &amp;amp;=x1 ;
%mend foo1 ;
%foo1()

%macro foo2() ;
  %*This does work cuz %STR masks at macro compile time ;
  %Let x2= %str(Example;Sample;);
  %put &amp;amp;=x2 ;
%mend foo2 ;
%foo2()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So why would both %STR() and %BQUOTE work in open code when masking a semicolon?:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let x1= %bquote(Example;Sample;);
%put &amp;amp;=x1 ;

%Let x2= %str(Example;Sample;);
%put &amp;amp;=x2 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure.&amp;nbsp; One thing I've heard is that the while the definition of compile-time and execution-time for a macro are clear (because macros are explicitly compiled and then executed), it's not as clear what those terms really mean for open macro statements.&amp;nbsp; Is an open %LET statement really &lt;EM&gt;compiled&lt;/EM&gt; rather than just being &lt;EM&gt;interpreted&lt;/EM&gt;?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tend to follow the rule that when you (a person reading code) can see the symbol to be masked, use %STR/%NRSTR.&amp;nbsp; When you cannot see the symbol to be masked, because it results from resolving a macro variable / expression, use %BQUOTE/%SUPERQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To my mind, it's odd that in open code, %BQUOTE is able to do the work that %STR() is intended to do.&amp;nbsp; Note that %STR() cannot do the work of %BQUOTE.&amp;nbsp; For example, below open code works with BQUOTE, but would not work with %STR() because you would have unmatched quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ; 
  call symputx("x","Example'Sample") ;
run ;               

%put %bquote(&amp;amp;x) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Some people use %BQUOTE in open code because it can mask a single quote or single parenthesis, without marking it with a % sign:&lt;/P&gt;
&lt;PRE&gt;%let x1=%bquote(Example'Sample) ;&lt;/PRE&gt;
&lt;P&gt;But I always use %STR in this setting, even at the cost of typing an extra %:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x2=%str(Example%'Sample) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Apr 2020 13:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643017#M191870</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-04-26T13:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643022#M191871</link>
      <description>&lt;P&gt;The only use I have ever found for %BQUOTE() is to add single quotes around macro variable values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sql_date = %bquote('%sysfunc(today(),yymmdd10.)');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In general if I want to add macro quoting to macro variable I use %SUPERQ().&amp;nbsp; If I want to add quoting to constant text I use %STR() or possible %NRSTR() and stick in the extra percent signs where needed.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 14:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643022#M191871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-26T14:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643029#M191873</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &amp;nbsp; One other way of putting quotes around macro variable values is using the &lt;STRONG&gt;%tslit&amp;nbsp;&lt;/STRONG&gt; function.&amp;nbsp; I believe this was available starting 9.4&amp;nbsp; release of SAS&amp;nbsp; when DS2&amp;nbsp; language became production-ready.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let sql_date = %tslit(%sysfunc(today(),yymmdd10.));&lt;BR /&gt;&lt;BR /&gt;%Put  &amp;amp;=sql_date;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I tend to use &lt;STRONG&gt;%bquote&amp;nbsp;&lt;/STRONG&gt; mostly when there is a need to resolve the value of macro variables within single quotes though there are other ways of doing this too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let x=1;

%Let y=%bquote('&amp;amp;x');

%Put &amp;amp;=y;   

&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thanks for your explanation. Sometimes this Macro Quoting subject tends to get trickier and a bit frustrating.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 15:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643029#M191873</guid>
      <dc:creator>pchegoor</dc:creator>
      <dc:date>2020-04-26T15:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why does %bquote work in this code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643067#M191877</link>
      <description>&lt;P&gt;I usually avoid the SAS written macros. They are usually in-efficient, probably because they were originally written for older versions of SAS.&lt;/P&gt;
&lt;P&gt;For example you could simplify TSLIT to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro tslit(value);
%sysfunc(quote(&amp;amp;value,%str(%')))
%mend tslit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See &lt;A href="https://github.com/sasutils/macros/blob/master/squote.sas" target="_self"&gt;%SQUOTE()&lt;/A&gt; macro.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 17:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-does-bquote-work-in-this-code/m-p/643067#M191877</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-26T17:01:52Z</dc:date>
    </item>
  </channel>
</rss>

