<?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: Question of using %str macro when pass macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637894#M189661</link>
    <description>&lt;P&gt;Tom already gave the correct answer: you need to %unquote() it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to add, I believe this is a bug (though I'm not sure SAS views it as such).&amp;nbsp; The value should be %unquoted automatically before it causes problems, but it doesn't always happen.&amp;nbsp; The rule I learned is that if you turn on MPRINT, and the code in the log looks valid while generating an error, try %UNQUOTE.&amp;nbsp; The SAS docs mention this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1f5qisx8mv9ygn1dikmgba1lmmu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1f5qisx8mv9ygn1dikmgba1lmmu.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;BLOCKQUOTE&gt;
&lt;H2 id="p17niy8lawk8txn1udu0f5vq89qi" class="xisDoc-title"&gt;What to Do When Automatic Unquoting Does Not Work&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;... In rare cases, masking text with a macro quoting function changes how the word scanner tokenizes the text. (The word scanner and tokenization are discussed in&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" title="" href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1lpbl12k9hhkxn1m721y05zgxhq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" data-docset-id="mcrolref" data-docset-version="9.4" data-original-href="p1lpbl12k9hhkxn1m721y05zgxhq.htm"&gt;SAS Programs and Macro Processing&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and and&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" title="" href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1l32rogpt4wmpn14liiqdqcbf1u.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" data-docset-id="mcrolref" data-docset-version="9.4" data-original-href="n1l32rogpt4wmpn14liiqdqcbf1u.htm"&gt;Macro Processing&lt;/A&gt;&lt;SPAN&gt;.) For example, a single or double quotation mark produced by resolution within the %BQUOTE function becomes a separate token. The word scanner does not use it as the boundary of a literal token in the input stack. If generated text that was once masked by the %BQUOTE function &lt;STRONG&gt;looks correct but SAS does not accept it, you might need to use the %UNQUOTE function to restore normal tokenization&lt;/STRONG&gt;. (emphasis added)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you use %TRIM the code works because %TRIM unquotes it.&amp;nbsp; As would %UPCASE, or other macro functions that don't explicitly quote the value they return.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Apr 2020 17:14:27 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2020-04-06T17:14:27Z</dc:date>
    <item>
      <title>Question of using %str macro when pass macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637872#M189656</link>
      <description>&lt;P&gt;Dear &lt;SPAN&gt;SAS experts&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use SAS for many years, but recently I meet following issue related to %str and cannot explain. Please see my SAS codes below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data abc_101;&lt;/DIV&gt;&lt;DIV&gt;a=3;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%macro test1(id= );&lt;/DIV&gt;&lt;DIV&gt;%put abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;data a;&lt;/DIV&gt;&lt;DIV&gt;set abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%mend test1;&lt;/DIV&gt;&lt;DIV&gt;%test1(id=%str(101));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;MLOGIC(TEST1): Beginning execution.&lt;BR /&gt;MLOGIC(TEST1): Parameter ID has value &amp;#1;101&amp;#2;&lt;BR /&gt;MLOGIC(TEST1): %PUT abc_&amp;amp;id.&lt;BR /&gt;abc_101&lt;BR /&gt;MPRINT(TEST1): data a;&lt;BR /&gt;MPRINT(TEST1): set abc_101;&lt;BR /&gt;ERROR: File WORK.ABC_.DATA does not exist.&lt;BR /&gt;MPRINT(TEST1): run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SAS log shows error that no&amp;nbsp;WORK.ABC_.DATA found. It seems like there is a blank in the front of &amp;amp;id which cause SAS cannot find ABC_ data. Why %put statement shows correct string, but set statement cannot. I also tried different solutions below:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;%macro test2(id= );&lt;/DIV&gt;&lt;DIV&gt;%let id=%trim(&amp;amp;id);&lt;/DIV&gt;&lt;DIV&gt;%put abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;data a;&lt;/DIV&gt;&lt;DIV&gt;set abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%mend test2;&lt;/DIV&gt;&lt;DIV&gt;%test2(id=%str(101));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%macro test3(id= );&lt;/DIV&gt;&lt;DIV&gt;%put abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;data a;&lt;/DIV&gt;&lt;DIV&gt;set abc_&amp;amp;id.;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%mend test3;&lt;/DIV&gt;&lt;DIV&gt;%test3(id=101);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Both works. I use %str function all the time to pass macro parameters, but now I am kind of confused. Does any experts can help me explain why we need to use %trim in the macro program or not use %str function. Thank you so much.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Apr 2020 15:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637872#M189656</guid>
      <dc:creator>Henry</dc:creator>
      <dc:date>2020-04-06T15:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Question of using %str macro when pass macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637882#M189659</link>
      <description>&lt;P&gt;The macro quoting is confusing the SAS parser into seeing multiple tokens instead of one token.&lt;/P&gt;
&lt;P&gt;You can add an call to the %unquote() macro function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set %unquote(abc_&amp;amp;id.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps easier you can build the name first and then use it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsname=abc_&amp;amp;id.;
set &amp;amp;dsname. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Apr 2020 16:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637882#M189659</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-06T16:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Question of using %str macro when pass macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637889#M189660</link>
      <description>&lt;P&gt;The string 101 does not need to be enclosed by %STR()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%STR() is only needed for certain special characters, as stated in the documentation.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 16:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637889#M189660</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-06T16:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Question of using %str macro when pass macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637894#M189661</link>
      <description>&lt;P&gt;Tom already gave the correct answer: you need to %unquote() it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to add, I believe this is a bug (though I'm not sure SAS views it as such).&amp;nbsp; The value should be %unquoted automatically before it causes problems, but it doesn't always happen.&amp;nbsp; The rule I learned is that if you turn on MPRINT, and the code in the log looks valid while generating an error, try %UNQUOTE.&amp;nbsp; The SAS docs mention this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1f5qisx8mv9ygn1dikmgba1lmmu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1f5qisx8mv9ygn1dikmgba1lmmu.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;BLOCKQUOTE&gt;
&lt;H2 id="p17niy8lawk8txn1udu0f5vq89qi" class="xisDoc-title"&gt;What to Do When Automatic Unquoting Does Not Work&lt;/H2&gt;
&lt;P&gt;&lt;SPAN&gt;... In rare cases, masking text with a macro quoting function changes how the word scanner tokenizes the text. (The word scanner and tokenization are discussed in&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" title="" href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p1lpbl12k9hhkxn1m721y05zgxhq.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" data-docset-id="mcrolref" data-docset-version="9.4" data-original-href="p1lpbl12k9hhkxn1m721y05zgxhq.htm"&gt;SAS Programs and Macro Processing&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;and and&amp;nbsp;&lt;/SPAN&gt;&lt;A tabindex="0" title="" href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1l32rogpt4wmpn14liiqdqcbf1u.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" data-docset-id="mcrolref" data-docset-version="9.4" data-original-href="n1l32rogpt4wmpn14liiqdqcbf1u.htm"&gt;Macro Processing&lt;/A&gt;&lt;SPAN&gt;.) For example, a single or double quotation mark produced by resolution within the %BQUOTE function becomes a separate token. The word scanner does not use it as the boundary of a literal token in the input stack. If generated text that was once masked by the %BQUOTE function &lt;STRONG&gt;looks correct but SAS does not accept it, you might need to use the %UNQUOTE function to restore normal tokenization&lt;/STRONG&gt;. (emphasis added)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you use %TRIM the code works because %TRIM unquotes it.&amp;nbsp; As would %UPCASE, or other macro functions that don't explicitly quote the value they return.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 17:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-of-using-str-macro-when-pass-macro-parameter/m-p/637894#M189661</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-04-06T17:14:27Z</dc:date>
    </item>
  </channel>
</rss>

