<?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: %qscan in macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518396#M3537</link>
    <description>&lt;P&gt;Using the macro variable value in a macro is not the issue. But you need to use macro quoting in that goofy string BEFORE passing it to the %qscan() function to avoid issues because of the embedded commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you generating that macro variable?&amp;nbsp; I am surprised that the %LET statement works in open code since it contains a macro comment in the middle of the value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to generate a macro variable with such mess of macro triggers inside of it then generate it from data.&amp;nbsp; Then later you can add macro quoting, for example by using %superq() macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;107  data _null_;
108    call symputx('teststr','a, %*b, %*c, %');
109  run;

NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds


110  %let teststr=%superq(teststr);
111  %put %qscan(&amp;amp;teststr.,2,%str(*));
b, %
112
113  %macro xx;
114  %put %qscan(&amp;amp;teststr.,2,%str(*));
115  %mend xx;
116  %xx;
b, %&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Dec 2018 14:14:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-12-04T14:14:35Z</dc:date>
    <item>
      <title>%qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518287#M3512</link>
      <description>&lt;P&gt;If I run this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let teststr=a, %*b, %*c, %;&lt;BR /&gt;%put %qscan(&amp;amp;teststr.,2,%str(*));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It runs perfectly&amp;nbsp;fine and return:&lt;/P&gt;
&lt;P&gt;b%&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However if I put this into a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro test;&lt;/P&gt;
&lt;P&gt;%let teststr=a, %*b, %*c, %;&lt;BR /&gt;%put %qscan(&amp;amp;teststr.,2,%str(*));&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%test&lt;/P&gt;
&lt;P&gt;Then there is no output. Does anyone know why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Jason&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 02:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518287#M3512</guid>
      <dc:creator>acmilannesta</dc:creator>
      <dc:date>2018-12-04T02:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518290#M3513</link>
      <description>&lt;P&gt;The eternal mystery that is SAS macro quoting. Why? I don't really know. I've never had much success with the escape characters, but I do know that do use the percent sign in this context, you need&amp;nbsp;&lt;EM&gt;%nrstr&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%let teststr = %nrstr(a%*b%*c);
%put %scan(&amp;amp;teststr, 2, %str(*));
%mend test;

%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use&amp;nbsp;&lt;EM&gt;%qscan&lt;/EM&gt;, or&amp;nbsp;&lt;EM&gt;%scan -&amp;nbsp;&lt;/EM&gt;it makes little difference.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 02:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518290#M3513</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-12-04T02:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518338#M3524</link>
      <description>&lt;P&gt;Both of your examples do not work:&lt;/P&gt;
&lt;PRE&gt;24         %let teststr=a, %*b, %*c, %;
25         %put %qscan(&amp;amp;teststr.,2,%str(*));
ERROR: Macro function %QSCAN has too many arguments.
 
26         
27         %macro test;
28         
29         %let teststr=a, %*b, %*c, %;
30         %put %qscan(&amp;amp;teststr.,2,%str(*));
31         %mend;
32         
33         
34         
35         %test
WARNING: Argument 2 to macro function %QSCAN is out of range.
&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 10:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518338#M3524</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-04T10:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518350#M3527</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22894"&gt;@acmilannesta&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your macro TEST doesn't work for two reasons:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;%* (inside a macro) is apparently interpreted as the beginning of a macro comment so that TESTSTR contains only two characters: &lt;STRONG&gt;a,&lt;/STRONG&gt; (see log below).&lt;/LI&gt;
&lt;LI&gt;The unquoted comma from the resolved value of TESTSTR is followed by another comma in the argument of %QSCAN, i.e., the second argument of %QSCAN is actually a null string, which causes the warning message "Argument 2 ... is out of range" (see Kurt Bremser's post).&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;1    options symbolgen;
2
3    %macro test;
4    %let teststr=a, %*b, %*c, %;
5    %put Length: %length(&amp;amp;teststr);
6    %mend;
7
8    %test
SYMBOLGEN:  Macro variable TESTSTR resolves to a,
Length: 2
9
10   %let teststr=a, %*b, %*c, %;
11   %put Length: %length(&amp;amp;teststr);
SYMBOLGEN:  Macro variable TESTSTR resolves to a, %*b, %*c, %
Length: 14&lt;/PRE&gt;
&lt;P&gt;Similarly, your open-code approach doesn't work either: After resolving &lt;FONT face="courier new,courier"&gt;&amp;amp;teststr.&lt;/FONT&gt; to a string containing unquoted commas %QSCAN has in fact "too many arguments" (see error message in Kurt Bremser's post). How did you obtain the result &lt;STRONG&gt;b%&lt;/STRONG&gt; given that this substring is not contained in the value of TESTSTR?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use %NRSTR, as recommended by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;, and&amp;nbsp;the code works inside and outside a macro (with&amp;nbsp;%SCAN and %QSCAN):&lt;/P&gt;
&lt;PRE&gt;1    options symbolgen;
2
3    %macro test;
4    %let teststr=%nrstr(a, %*b, %*c, %%);
5    %put %scan(&amp;amp;teststr.,2,%str(*));
6    %mend;
7
8    %test
SYMBOLGEN:  Macro variable TESTSTR resolves to a, %*b, %*c, %
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
b, %
9
10   %let teststr=%nrstr(a, %*b, %*c, %%);
11   %put %scan(&amp;amp;teststr.,2,%str(*));
SYMBOLGEN:  Macro variable TESTSTR resolves to a, %*b, %*c, %
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
b, %&lt;/PRE&gt;
&lt;P&gt;Note that I used the double percent sign so as to avoid that the closing parenthesis is masked and&amp;nbsp;thus not recognized.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 11:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518350#M3527</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-04T11:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518396#M3537</link>
      <description>&lt;P&gt;Using the macro variable value in a macro is not the issue. But you need to use macro quoting in that goofy string BEFORE passing it to the %qscan() function to avoid issues because of the embedded commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you generating that macro variable?&amp;nbsp; I am surprised that the %LET statement works in open code since it contains a macro comment in the middle of the value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to generate a macro variable with such mess of macro triggers inside of it then generate it from data.&amp;nbsp; Then later you can add macro quoting, for example by using %superq() macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;107  data _null_;
108    call symputx('teststr','a, %*b, %*c, %');
109  run;

NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds


110  %let teststr=%superq(teststr);
111  %put %qscan(&amp;amp;teststr.,2,%str(*));
b, %
112
113  %macro xx;
114  %put %qscan(&amp;amp;teststr.,2,%str(*));
115  %mend xx;
116  %xx;
b, %&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 14:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518396#M3537</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-04T14:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518421#M3540</link>
      <description>&lt;P&gt;Thank you so mcuh,&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_self"&gt;FreelanceReinha&lt;WBR /&gt;rd&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;It works!&amp;nbsp;I tried to use %nrstr() as well, but the piece I miss is the trailing % sign. Could you explain a little bit more about the rationale:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;"Note that I used the double percent sign so as to avoid that the closing parenthesis is masked and&amp;nbsp;thus not recognized."&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 14:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518421#M3540</guid>
      <dc:creator>acmilannesta</dc:creator>
      <dc:date>2018-12-04T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518429#M3541</link>
      <description>&lt;P&gt;Thank you, Tom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That works great. I am still a beginner for SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please tell what's the difference between a %let statement and a call symputx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does a %superq could mask some macro symbols such as % and *. I tried to use %bquote and %nrbquote, but that doesn't work.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 14:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518429#M3541</guid>
      <dc:creator>acmilannesta</dc:creator>
      <dc:date>2018-12-04T14:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518447#M3549</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22894"&gt;@acmilannesta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, Tom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That works great. I am still a beginner for SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please tell what's the difference between a %let statement and a call symputx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does a %superq could mask some macro symbols such as % and *. I tried to use %bquote and %nrbquote, but that doesn't work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A %LET statement is macro code. CALL SYMPUTX() is a function you can use with normal SAS code instead.&lt;/P&gt;
&lt;P&gt;There are rules for how the SAS macro processor parses the text to see if there is any work for it. That leads to the need for the extra % mentioned so that it wouldn't see the percent in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as instructions to treat the right parenthesis as part of the string instead of the closing parenthesis to the macro function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in regular SAS code strings are enclosed in quotes.&amp;nbsp; And if you use single quotes then the macro processor ignores them. So by using a data step to set the macro variable value you don't need to worry if the value has any characters that the macro processor considers special.&amp;nbsp; However using CALL SYMPUTX() will not inject any macro quoting into the value of the macro variable.&amp;nbsp; So you need to take care when using it in macro code since it might contain characters, like comma in this case, that will have a special meaning if not macro quoted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another trick set a macro variable to avoid worrying about a lot of the macro quoting that you can use in a place where you could not add a data step.&amp;nbsp; Enclose the string in single quotes and then use the %sysfunc(), or if you need macro quoting the %qsysfunc(), macro function to call the DEQUOTE() function to remove the quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar=%qsysfunc(dequote('A %,B%*'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 15:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518447#M3549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-04T15:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518451#M3550</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22894"&gt;@acmilannesta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;I tried to use %nrstr() as well, but the piece I miss is the trailing % sign. Could you explain a little bit more about the rationale:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;"Note that I used the double percent sign so as to avoid that the closing parenthesis is masked and&amp;nbsp;thus not recognized."&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Normally you use the combination &lt;STRONG&gt;%)&lt;/STRONG&gt; in a %NRSTR (or&amp;nbsp;&lt;SPAN&gt;%STR)&amp;nbsp;&lt;/SPAN&gt;call&amp;nbsp;to make an unmatched closed parenthesis a part of the value of a macro variable. Without the percent sign masking it, the parenthesis would be interpreted as the closing parenthesis of the %NRSTR(...&lt;STRONG&gt;)&lt;/STRONG&gt; call (see documentation &lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0pnc7p9n4h6g5n16g6js048nhfl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p0guhqnlr7q0g2n18pdmg0p6b4up" target="_blank"&gt;Using Unmatched Quotation Marks and Parentheses with %STR and %NRSTR&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example, however, the parenthesis &lt;EM&gt;is&lt;/EM&gt; meant to be the&amp;nbsp;&lt;SPAN&gt;closing parenthesis of the %NRSTR(...&lt;/SPAN&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;call and the percent sign is &lt;EM&gt;not&lt;/EM&gt; meant as a masking tool for it.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;To explain this special requirement to the macro processor, I used the double percent sign. The first percent sign masks the second, so the second is regarded as text, not as a macro trigger. Then, the closing parenthesis is not masked and works as desired. (See the note at the bottom of the short section &lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=p0pnc7p9n4h6g5n16g6js048nhfl.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p031r0j9xax3e0n17xtmbo16x13l" target="_blank"&gt;Using % Signs with %STR&lt;/A&gt;&amp;nbsp;in the documentation.)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 15:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518451#M3550</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-04T15:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518455#M3552</link>
      <description>I see. That's why I got a warning message telling me an unclosed parenthesis. Many thx!</description>
      <pubDate>Tue, 04 Dec 2018 15:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518455#M3552</guid>
      <dc:creator>acmilannesta</dc:creator>
      <dc:date>2018-12-04T15:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: %qscan in macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518456#M3553</link>
      <description>Thank you, Tom!&lt;BR /&gt;Yes, the "dequote" function is really a nice way to bypass all these worries of macro symbols. Lesson learned!</description>
      <pubDate>Tue, 04 Dec 2018 15:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/qscan-in-macro/m-p/518456#M3553</guid>
      <dc:creator>acmilannesta</dc:creator>
      <dc:date>2018-12-04T15:48:59Z</dc:date>
    </item>
  </channel>
</rss>

