<?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: Macro for dynamic number of variables in a GROUP BY in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169778#M32566</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;/* Group/order variables */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; NAME &lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :grp separated by ','&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="SASHELP"&lt;BR /&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp; MEMNAME="CARS"&lt;BR /&gt;&amp;nbsp; and name in ('Make','Origin');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Where variables */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; NAME &lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :filter separated by ' is not null and '&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="SASHELP"&lt;BR /&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp; MEMNAME="CARS"&lt;BR /&gt;&amp;nbsp; and name in ('Make','Origin');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select &amp;amp;vars,sum(msrp) as sales&lt;BR /&gt;from have&lt;BR /&gt;where &amp;amp;filter is not null&lt;BR /&gt;group by &amp;amp;grp&lt;BR /&gt;order by &amp;amp;grp;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 04 Oct 2014 02:07:22 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-10-04T02:07:22Z</dc:date>
    <item>
      <title>Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169768#M32556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've currently have a macro written for a single variable that looks like:&lt;/P&gt;&lt;P&gt;%macro singlevar(var)&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Proc sql ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create table temp as select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;var,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(Sales) as Sales&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From DataTable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Group by &amp;amp;var&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Order by &amp;amp;var&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; quit ;&lt;/P&gt;&lt;P&gt;%mend ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm currently lost trying to write the macro to be dynamic with essentially an infinite number of variables to group by.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro Multivar(var1, var2, var.etc.)&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Proc sql ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create table temp as select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;var,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;var2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;var.etc,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(Sales) as Sales&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; From DataTable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Group by &amp;amp;var,&amp;nbsp; &amp;amp;var2,&amp;nbsp; &amp;amp;var.etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Order by &amp;amp;var,&amp;nbsp;&amp;nbsp; &amp;amp;var2,&amp;nbsp; &amp;amp;var.etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&amp;nbsp; quit ;&lt;/P&gt;&lt;P&gt;%mend ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 15:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169768#M32556</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-02T15:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169769#M32557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wrap up grouping variables in a macro variable and use that in group by and order by something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; NAME &lt;/P&gt;&lt;P&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :vars separated by ','&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;/P&gt;&lt;P&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="SASHELP"&lt;/P&gt;&lt;P&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp; MEMNAME="CARS"&lt;/P&gt;&lt;P&gt;&amp;nbsp; and name in ('Make','Origin');&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select &amp;amp;vars,sum(msrp) as sales&lt;/P&gt;&lt;P&gt;from sashelp.cars&lt;/P&gt;&lt;P&gt;group by &amp;amp;vars&lt;/P&gt;&lt;P&gt;order by &amp;amp;vars;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 15:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169769#M32557</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-02T15:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169770#M32558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great thank you for the quick reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How would it work if I wanted to put in a criteria? when I add &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Where &amp;amp;vars not in ('')&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;it will give me an error in this case.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select &amp;amp;vars,sum(msrp) as sales&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from sashelp.cars&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Where &amp;amp;vars not in ('') &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;group by &amp;amp;vars&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;order by &amp;amp;vars;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 16:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169770#M32558</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-02T16:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169771#M32559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might consider something like this.&amp;nbsp; However you can get the same thing with much less work using PROC SUMMARY.&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; ex(&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;arg&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;arg2&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;)&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; arg = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(scan(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%superq&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;arg&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;,1,&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;%)%(&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;));&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; NOTE: &amp;amp;=arg;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table a&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as select &lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;amp;arg&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;, &amp;amp;arg2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.class&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by &lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;amp;arg&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by &lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;amp;arg&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; ex;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;options&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;mprint&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;%&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style="color: #000000; background-color: #ffffff;"&gt;ex&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;((age,sex),sum(weight) as sum_weight);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 16:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169771#M32559</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-10-02T16:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169772#M32560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can actually use the PARMBUF option in the macro declaration, and pass an arbitrary number of parameters, which you loop through in the macro body. See attached. (for some reason I cannot paste into this comment, or I would do so).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 20:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169772#M32560</guid>
      <dc:creator>NeilGundel</dc:creator>
      <dc:date>2014-10-02T20:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169773#M32561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, this is very interesting, I will look into this for my current problem. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 16:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169773#M32561</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-03T16:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169774#M32562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Personally I use space delimited lists of variables.&amp;nbsp; Not only do they not confuse the macro calls they are more useful in normal SAS statements (like VAR, TABLES, KEEP , DROP etc.).&amp;nbsp; If you need to use the list in SQL code with its insistence on using commas as delimiters than just convert the value inside the macro rather than forcing the macro user to insert the commas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; multivar(varlist)&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; varlist=&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(tranwrd(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(compbl(&amp;amp;varlist)),&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;( ),&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(,)));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;NOPRINT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; temp &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;varlist&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , sum(sales) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sales&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datatable&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;varlist&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;order&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;varlist&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 23:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169774#M32562</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-03T23:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169775#M32563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply Tom. &lt;/P&gt;&lt;P&gt;In this case how would you include conditions on the varlist such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Where var1 is not null and var2 is not null etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose its like breaking the varlist down into individual variables..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 23:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169775#M32563</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-03T23:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169776#M32564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TRANWRD() works well for that also (if the list if not too long).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; varlist=var1 var2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; where &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(tranwrd(&amp;amp;varlist,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;( ),&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%str&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;( is not null AND ))) is not null ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Oct 2014 00:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169776#M32564</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-04T00:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169777#M32565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For your example application SQL is probably not the preferred solution.&amp;nbsp; Use PROC SUMMARY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sum(classvars,sumvars,in,out);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;summary&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;nway&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=&amp;amp;in ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;class&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;classvars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;sumvars ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;output&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;=&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;out&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;= ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;sum&lt;/EM&gt;&lt;/STRONG&gt;(classvars=sex age,sumvars=height weight,in=sashelp.class,out=sum1);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Oct 2014 00:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169777#M32565</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-04T00:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169778#M32566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;/* Group/order variables */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; NAME &lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :grp separated by ','&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="SASHELP"&lt;BR /&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp; MEMNAME="CARS"&lt;BR /&gt;&amp;nbsp; and name in ('Make','Origin');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Where variables */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select&amp;nbsp; NAME &lt;BR /&gt;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp; :filter separated by ' is not null and '&lt;BR /&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;BR /&gt;&amp;nbsp; where&amp;nbsp;&amp;nbsp; LIBNAME="SASHELP"&lt;BR /&gt;&amp;nbsp; and&amp;nbsp;&amp;nbsp; MEMNAME="CARS"&lt;BR /&gt;&amp;nbsp; and name in ('Make','Origin');&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select &amp;amp;vars,sum(msrp) as sales&lt;BR /&gt;from have&lt;BR /&gt;where &amp;amp;filter is not null&lt;BR /&gt;group by &amp;amp;grp&lt;BR /&gt;order by &amp;amp;grp;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Oct 2014 02:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169778#M32566</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-04T02:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169779#M32567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Tranwrd() solution worked great!.. but of course I want to complicate things further...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to add a Proc Sql step to JOIN tables based on the variables in the varlist.&lt;/P&gt;&lt;P&gt;In this case it will require&amp;nbsp; the string to output the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on T1.&amp;amp;var1=T2.&amp;amp;var1 and T1.&amp;amp;var2=T2.&amp;amp;var2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to use tranwrd() again to get this, but I think it requires an additional loop..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 20:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169779#M32567</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-08T20:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169780#M32568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might need to have a %DO loop .&lt;/P&gt;&lt;P&gt;%let prefix=ON ;&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(count(&amp;amp;varlist));&lt;/P&gt;&lt;P&gt; &amp;amp;prefix T1.%scan(&amp;amp;varlist,&amp;amp;i) = T2.%scan(&amp;amp;varlist,&amp;amp;i)&lt;/P&gt;&lt;P&gt;%let prefix=AND ;&lt;/P&gt;&lt;P&gt;%end ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Oct 2014 22:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169780#M32568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-08T22:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169781#M32569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having troubles incorporating this into my macro's proc sql statement. I'm not sure where i'm going wrong with this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example code:&lt;/P&gt;&lt;P&gt;%macro Test(variables) ;&lt;/P&gt;&lt;P&gt;%let varlist=%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;variables)),%str( ),%str(,)));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;/P&gt;&lt;P&gt;Create table Table3 as Select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T2.temp&lt;/P&gt;&lt;P&gt;FROM Table1 as T1&lt;/P&gt;&lt;P&gt;LEFT JOIN Table2 as T2&lt;/P&gt;&lt;P&gt;%let prefix=ON ;&lt;/P&gt;&lt;P&gt;%do i=1 %to %sysfunc(count(&amp;amp;varlist));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;prefix T1.%scan(&amp;amp;varlist,&amp;amp;i) = T2.%scan(&amp;amp;varlist,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prefix=AND ;&lt;/P&gt;&lt;P&gt;%end ;&lt;/P&gt;&lt;P&gt;Order by &amp;amp;varlist&lt;/P&gt;&lt;P&gt;; quit ;&lt;/P&gt;&lt;P&gt;%mend ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%test(var1 var2) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the log, I get the error "Found "Order" when expecting ON, so it seems like the's skipping the whole section of the loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 16:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169781#M32569</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-09T16:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169782#M32570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it works beautifully when i try it alone :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro Words(Word_list);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let prefix=ON ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to %sysfunc(countw(&amp;amp;Word_List));&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put &amp;amp;&amp;amp;prefix T1.%scan(&amp;amp;Word_List,&amp;amp;i) = T2.%scan(&amp;amp;Word_List,&amp;amp;i) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let prefix=AND ;&lt;/P&gt;&lt;P&gt;%end ;&lt;/P&gt;&lt;P&gt;%mend ; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%words(var1 var2) ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 16:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169782#M32570</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-09T16:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169783#M32571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have an extra semi-colon.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 17:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169783#M32571</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-09T17:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169784#M32572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure that's it.. I'm still getting the same error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro Test(variables) ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let varlist=%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;variables)),%str( ),%str(,)));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;PROC SQL ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Create table Table3 as Select&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T1.*,&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; T2.temp&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;FROM Table1 as T1&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;LEFT JOIN Table2 as T2&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let prefix=ON ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do i=1 %to %sysfunc(count(&amp;amp;varlist));&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;prefix T1.%scan(&amp;amp;varlist,&amp;amp;i) = T2.%scan(&amp;amp;varlist,&amp;amp;i)&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let prefix=AND ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Order by &amp;amp;varlist&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;; quit ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%test(var1 var2) ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 17:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169784#M32572</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-09T17:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169785#M32573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have changed the value of VARLIST to be the version with comma. So you need to protect the commas from being read by the %SCAN() function.&amp;nbsp; You could add quoting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let x=a,b ;&lt;/P&gt;&lt;P&gt;%put %scan(%superq(x),1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or you could just use two different macro variables for the list with and without commas.&lt;/P&gt;&lt;P&gt;%local varlistc ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let varlistc=%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;variables)),%str( ),%str(,)));&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 18:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169785#M32573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-10-09T18:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for dynamic number of variables in a GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169786#M32574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Tom, i've gotten the code to work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 18:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-dynamic-number-of-variables-in-a-GROUP-BY/m-p/169786#M32574</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2014-10-09T18:15:52Z</dc:date>
    </item>
  </channel>
</rss>

