<?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: GROUP BY a macro variable list (except one variable) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488710#M127418</link>
    <description>Exactly what I needed, many thanks!</description>
    <pubDate>Tue, 21 Aug 2018 20:33:44 GMT</pubDate>
    <dc:creator>x2PSx</dc:creator>
    <dc:date>2018-08-21T20:33:44Z</dc:date>
    <item>
      <title>GROUP BY a macro variable list (except one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488678#M127404</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an SQL procedure in which I want to aggregate data with a group by procedure. I use a macro variable list because the level of aggregation needed might change. However, there is always one variable that I want to exclude from that list at that step and I don't know how to proceed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have right now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET CATEG = %str(VAR1, VAR2, VAR3, EXCL);
%LET CATEG2 = %str(VAR1, VAR2, VAR3);
proc sql noprint;
	create table WANT as
		select  &amp;amp;CATEG.,
				sum(Nobs_last) as CAT_Nobs_last,
				sum(Nobs) as CAT_Nobs

			from HAVE
				group by &amp;amp;CATEG2.
				order by &amp;amp;CATEG.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I would like to have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET CATEG = %str(VAR1, VAR2, VAR3, EXCL);
proc sql noprint;
	create table WANT as
		select  &amp;amp;CATEG.,
				sum(Nobs_last) as CAT_Nobs_last,
				sum(Nobs) as CAT_Nobs

			from HAVE
				group by &amp;amp;CATEG. [with an function that let me exclude the var EXCL]
				order by &amp;amp;CATEG.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you very much for your time, Cheers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 19:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488678#M127404</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2018-08-21T19:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP BY a macro variable list (except one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488704#M127417</link>
      <description>&lt;P&gt;I would recommend building a new macro variable with something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let categ2 = %sysfunc(tranwrd(&amp;amp;categ.,%str(, EXCL), ));
%put &amp;amp;categ2.;&lt;/PRE&gt;
&lt;P&gt;WARNING: The above is CASE SENSITIVE and if you use Excl EXcl or others it will fail. This can be addressed by %upcase your categ variable. variable names in SAS aren't case sensitive so no issue with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WARNING: The above is also space sensitive. If you do not always include ", EXCL" with one space it will fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would create a different variable instead of attempting an inline "function", whatever that might have been, because you can get the value of a macro variable when you need to debug something.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 20:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488704#M127417</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-21T20:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP BY a macro variable list (except one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488710#M127418</link>
      <description>Exactly what I needed, many thanks!</description>
      <pubDate>Tue, 21 Aug 2018 20:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/GROUP-BY-a-macro-variable-list-except-one-variable/m-p/488710#M127418</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2018-08-21T20:33:44Z</dc:date>
    </item>
  </channel>
</rss>

