<?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: String list as Macro Parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69013#M14986</link>
    <description>One option is to enclose your %LET SC =    assignment statement with %STR( ) -- rather than on the macro invocation statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry</description>
    <pubDate>Tue, 13 Jan 2009 18:21:41 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-01-13T18:21:41Z</dc:date>
    <item>
      <title>String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69012#M14985</link>
      <description>Good Afternoon!   &lt;BR /&gt;
&lt;BR /&gt;
I have list of parameters that I am trying to pass into a macro as a single parameter.  I'm using %STR() around the variable since it is comma separated but for some reason it's still seeing the commas in the variable.&lt;BR /&gt;
&lt;BR /&gt;
%let sc = '1224','1612','9603','9919','1920';&lt;BR /&gt;
&lt;BR /&gt;
%macro sb_metrics(sb=%str('9999'), sb_txt_shrt=none, sb_txt_lng=none);&lt;BR /&gt;
, count(distinct case when C.itm_sbrnd_cd in (&amp;amp;sb) then A.lbi_indv_id else . end)&amp;amp;factor as &amp;amp;sb_txt_shrt._indv_cnt&lt;BR /&gt;
/* more code here but same concept */.&lt;BR /&gt;
&amp;amp;factor as &amp;amp;sb_txt_shrt._indv_cnt&lt;BR /&gt;
%mend sb_metrics;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table Restage_Results_&amp;amp;Theme_TY_Name as&lt;BR /&gt;
select&lt;BR /&gt;
  /* more code here but this functions normally */ &lt;BR /&gt;
  %sb_metrics(sb=%str(&amp;amp;sc), sb_txt_shrt=sc, sb_txt_lng=Signature)&lt;BR /&gt;
from perm.trans_&amp;amp;Theme_TY_Name._B as A&lt;BR /&gt;
  left outer join Restage as B on A.lgcy_sto_nbr = B.Store&lt;BR /&gt;
  join perm.sku_xref as C on A.SKU_XREF_ID = C.sku_xref_id&lt;BR /&gt;
  left outer join deciles_&amp;amp;Theme_TY_Name as D on A.lbi_indv_id = D.lbi_indv_id&lt;BR /&gt;
group by 1&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Here is the error I keep getting.  &lt;BR /&gt;
&lt;BR /&gt;
ERROR: All positional parameters must precede keyword parameters.&lt;BR /&gt;
574          %sb_metrics(sb=%str(&amp;amp;sc), sb_txt_shrt=sc, sb_txt_lng=Signature)&lt;BR /&gt;
                                                                           -&lt;BR /&gt;
                                                                           79&lt;BR /&gt;
ERROR 79-322: Expecting a (.&lt;BR /&gt;
&lt;BR /&gt;
I've used this type of coding proceedure before and it's worked (I was using the old one as an example) but for some reason I just can't seem to get it to work. &lt;BR /&gt;
&lt;BR /&gt;
Any suggestions would be greatly appreciated!  Thank you!!</description>
      <pubDate>Tue, 13 Jan 2009 17:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69012#M14985</guid>
      <dc:creator>daveryBBW</dc:creator>
      <dc:date>2009-01-13T17:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69013#M14986</link>
      <description>One option is to enclose your %LET SC =    assignment statement with %STR( ) -- rather than on the macro invocation statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry</description>
      <pubDate>Tue, 13 Jan 2009 18:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69013#M14986</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-01-13T18:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69014#M14987</link>
      <description>have a look at the macro option parmbuff &lt;BR /&gt;
It fills the macro variable SYSPBUFF with the macro parameter list (including the parentheses)&lt;BR /&gt;
&lt;BR /&gt;
%macro sb_metrics(sb=%str('9999'), sb_txt_shrt=none, sb_txt_lng=none)&lt;BR /&gt;
   /parmbuff;&lt;BR /&gt;
%put %quote(&amp;amp;syspbuff) ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 13 Jan 2009 18:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69014#M14987</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-01-13T18:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69015#M14988</link>
      <description>Scott - I thought about that but the variable is also being used to go into a SAS CONNECT query to another DBMS, which would throw an error at the %STR() function, since it's SAS and not native to the DBMS.&lt;BR /&gt;
&lt;BR /&gt;
PeterC - Thank you - I'd never seen that option before, being a self taught macro coder.  When I tested it though, it appears that because of how I'm using the macro to write lines within my PROC SQL statement instead of being around the PROC SQL, the code is erroring out before it gets to the part of printing the &amp;amp;syspbuff to the log. So, nothing is going to the log.  I do intend to use this parameter in debugging other macro code though!&lt;BR /&gt;
&lt;BR /&gt;
Apart from this post, I was doing some digging on another topic and think I might have found something that works in this case to fix my issue.  I was reading somewhere where the person used %QUOTE() in conjunction with %UNQUOTE() for something else, so I tried it.   I used %QUOTE() in the macro call and %UNQUOTE in the macro itself and when executed the code didn't throw any errors as of yet.  The log shows it still running so I'll have to see how it finishes.</description>
      <pubDate>Tue, 13 Jan 2009 18:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69015#M14988</guid>
      <dc:creator>daveryBBW</dc:creator>
      <dc:date>2009-01-13T18:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69016#M14989</link>
      <description>This looks like a timing thing, so try using a %bquote instead of %str e.g.&lt;BR /&gt;
&lt;BR /&gt;
%let sc = '1224','1612','9603','9919','1920';&lt;BR /&gt;
%sb_metrics(sb=%bquote(&amp;amp;sc), etc, etc, etc);&lt;BR /&gt;
&lt;BR /&gt;
The %bquote masks the same items as %str, but %str masks constant text instead of a resolved value.  The %str works during compilation time but the &lt;BR /&gt;
%bquote works during execution time.</description>
      <pubDate>Wed, 14 Jan 2009 19:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69016#M14989</guid>
      <dc:creator>PatrickG</dc:creator>
      <dc:date>2009-01-14T19:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: String list as Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69017#M14990</link>
      <description>You can avoid the use of QUOTING functions in this case with the use of parenthesis().  Notice the change in your code where &amp;amp;SB is used in the macro, I removed the parenthesis because they are now part of the value.  &lt;BR /&gt;
&lt;BR /&gt;
If you had a situation where the parenthiesis were not needed they could be removed with %qsubstr(%superq(sb),2,%length(%superq(sb))-2);&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
433  %let sc = '1224','1612','9603','9919','1920';&lt;BR /&gt;
434  %let FACTOR = ?; **Where is this?;&lt;BR /&gt;
435&lt;BR /&gt;
436  %macro sb_metrics(sb=('9999'), sb_txt_shrt=none,&lt;BR /&gt;
436! sb_txt_lng=none);&lt;BR /&gt;
437     %put _LOCAL_;&lt;BR /&gt;
438     %put , count(distinct case when C.itm_sbrnd_cd in &amp;amp;sb&lt;BR /&gt;
438! then A.lbi_indv_id else . end)&amp;amp;factor as&lt;BR /&gt;
438! &amp;amp;sb_txt_shrt._indv_cnt&lt;BR /&gt;
439     /* more code here but same concept */.&lt;BR /&gt;
440     &amp;amp;factor as &amp;amp;sb_txt_shrt._indv_cnt&lt;BR /&gt;
441     ;&lt;BR /&gt;
442  %mend sb_metrics;&lt;BR /&gt;
443&lt;BR /&gt;
444  %sb_metrics(sb=(&amp;amp;sc))&lt;BR /&gt;
SB_METRICS SB_TXT_SHRT none&lt;BR /&gt;
SB_METRICS SB_TXT_LNG none&lt;BR /&gt;
SB_METRICS SB ('1224','1612','9603','9919','1920')&lt;BR /&gt;
, count(distinct case when C.itm_sbrnd_cd in&lt;BR /&gt;
('1224','1612','9603','9919','1920') then A.lbi_indv_id else .&lt;BR /&gt;
end)? as none_indv_cnt    .    ? as none_indv_cnt&lt;BR /&gt;
[pre]</description>
      <pubDate>Fri, 16 Jan 2009 13:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-list-as-Macro-Parameter/m-p/69017#M14990</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-01-16T13:53:32Z</dc:date>
    </item>
  </channel>
</rss>

