<?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 Calling a Macro variable from a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29675#M5627</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have several lists of ID numbers that are stored in macro variables.&amp;nbsp; I have a macro that executes an SQL query and when I call the macro, I need to be able to specify which list to use.&amp;nbsp; If I just put the macro variable in the macro call, I get an error that says more arguments have been passed than are specified.&amp;nbsp; An example of what I have is below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let list1 = 101,102,103,104,105;&lt;/P&gt;&lt;P&gt;%let list2 = 106,107,108,109,110;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(list);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to mysql(server);&lt;/P&gt;&lt;P&gt; create table table1 as select * from connection to mysql (&lt;/P&gt;&lt;P&gt;select * from dataset where id in (&amp;amp;list));&lt;/P&gt;&lt;P&gt;disconnect from mysql;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test(&amp;amp;list1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully this makes sense with what I am trying to do.&amp;nbsp; Anyone have an idea of how this can work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Oct 2011 12:35:45 GMT</pubDate>
    <dc:creator>jlcalbre</dc:creator>
    <dc:date>2011-10-14T12:35:45Z</dc:date>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29675#M5627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have several lists of ID numbers that are stored in macro variables.&amp;nbsp; I have a macro that executes an SQL query and when I call the macro, I need to be able to specify which list to use.&amp;nbsp; If I just put the macro variable in the macro call, I get an error that says more arguments have been passed than are specified.&amp;nbsp; An example of what I have is below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let list1 = 101,102,103,104,105;&lt;/P&gt;&lt;P&gt;%let list2 = 106,107,108,109,110;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(list);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to mysql(server);&lt;/P&gt;&lt;P&gt; create table table1 as select * from connection to mysql (&lt;/P&gt;&lt;P&gt;select * from dataset where id in (&amp;amp;list));&lt;/P&gt;&lt;P&gt;disconnect from mysql;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test(&amp;amp;list1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully this makes sense with what I am trying to do.&amp;nbsp; Anyone have an idea of how this can work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 12:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29675#M5627</guid>
      <dc:creator>jlcalbre</dc:creator>
      <dc:date>2011-10-14T12:35:45Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29676#M5628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Try using&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test(list1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you add &amp;amp; before that, macro variable is resulved already in this step, that is why it fails.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 12:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29676#M5628</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2011-10-14T12:58:05Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29677#M5629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is getting the commas past the macro call.&lt;/P&gt;&lt;P&gt;You can quote them.&lt;/P&gt;&lt;P&gt;&amp;nbsp; %test(%str(&amp;amp;list1));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should also just test whether you need the commas at all.&amp;nbsp; You do not need them for the IN operator in normal SAS, but they might be required by MYSQL.&lt;/P&gt;&lt;P&gt;In SAS code you can write :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp; where id in (101 102 103);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29677#M5629</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-14T13:00:59Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29678#M5630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For this to work the macro code will need to change to :&lt;/P&gt;&lt;P&gt;... in (&amp;amp;&amp;amp;&amp;amp;list) ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29678#M5630</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-14T13:03:53Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29679#M5631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The commas are rquired since this is a pass through to mysql.&amp;nbsp; The quoting worked perfectly.&amp;nbsp; I figured there was something simple I was missing.&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 14:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29679#M5631</guid>
      <dc:creator>jlcalbre</dc:creator>
      <dc:date>2011-10-14T14:14:59Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29680#M5632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; change&lt;/P&gt;&lt;P&gt;%let list1 = 101,102,103,104,105;&lt;/P&gt;&lt;P&gt;%let list2 = 106,107,108,109,110;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to &lt;/P&gt;&lt;P&gt;%let list1 = %str(101,102,103,104,105);&lt;/P&gt;&lt;P&gt;%let list2 = %str(106,107,108,109,110);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 14:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29680#M5632</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2011-10-14T14:23:20Z</dc:date>
    </item>
    <item>
      <title>Calling a Macro variable from a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29681#M5633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is that when you call the macro, the commas in the macro variable make it look as if there are too many parameters for the macro:&lt;/P&gt;&lt;PRE&gt;%let list1 = 101,102,103,104,105;
%test(&amp;amp;list1);&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will resolve to: &lt;/P&gt;&lt;PRE&gt;%test(101,102,103,104,105);&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and that looks like a macro call with &lt;SPAN style="text-decoration: underline;"&gt;several&lt;/SPAN&gt; parameters, not just one.&amp;nbsp; You will need to mask the commas using an execution-time macro quoting function like SUPERQ.&amp;nbsp; If you choose SUPERQ, your code would look like this: &lt;/P&gt;&lt;PRE&gt; 
%let list1 = 101,102,103,104,105;
%let list2 = 106,107,108,109,110;
 
%macro test(list);
 
proc sql;
connect to mysql(server);
create table table1 as select * from connection to mysql (
select * from dataset where id in (&amp;amp;list));
disconnect from mysql;
quit;
 
%mend;
 
%test(%SUPERQ(list1));&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tested this solution, and it works fine in SAS9.3 on Windows 7.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Oct 2011 13:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-Macro-variable-from-a-macro-variable/m-p/29681#M5633</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-10-18T13:13:27Z</dc:date>
    </item>
  </channel>
</rss>

