<?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 PROC SQL ... GROUP BY question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-GROUP-BY-question/m-p/12762#M1741</link>
    <description>Does anyone know if there is any shortcut in a PROC SQL ... GROUP BY statement so that if you have more than just a few columns that you need to group by, that you can do something like this:&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL&lt;BR /&gt;
CREATE TABLE x AS &lt;BR /&gt;
    SELECT col1, col2 ... col10, sum(numcol) as sumNumCol&lt;BR /&gt;
    FROM y&lt;BR /&gt;
    GROUP BY 1-10&lt;BR /&gt;
;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
I know that you can write the GROUP BY out (col1, col2, col3 ... etc.) as well as write it as GROUP BY 1, 2, 3, 4, 5 ...  but if you have a whole slew of columns that you have to group by, is there a shortcut similar to what you can do in a DATA step with setting up an ARRAY but with the numeric representation instead of the column names.&lt;BR /&gt;
&lt;BR /&gt;
I'm sure that there is probably a more SAS friendly way (i.e. non PROC SQL) to do what I'm trying to do however PROC SQL is really the only way to do COUNT(DISTINCT column) in a semi-efficient manner.&lt;BR /&gt;
&lt;BR /&gt;
My guess is that I'm probably just going to have to continue typing everything out, but I figured I'd ask the question.  If you never ask, you'll never truely know.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Mon, 30 Mar 2009 14:46:16 GMT</pubDate>
    <dc:creator>daveryBBW</dc:creator>
    <dc:date>2009-03-30T14:46:16Z</dc:date>
    <item>
      <title>PROC SQL ... GROUP BY question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-GROUP-BY-question/m-p/12762#M1741</link>
      <description>Does anyone know if there is any shortcut in a PROC SQL ... GROUP BY statement so that if you have more than just a few columns that you need to group by, that you can do something like this:&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL&lt;BR /&gt;
CREATE TABLE x AS &lt;BR /&gt;
    SELECT col1, col2 ... col10, sum(numcol) as sumNumCol&lt;BR /&gt;
    FROM y&lt;BR /&gt;
    GROUP BY 1-10&lt;BR /&gt;
;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
I know that you can write the GROUP BY out (col1, col2, col3 ... etc.) as well as write it as GROUP BY 1, 2, 3, 4, 5 ...  but if you have a whole slew of columns that you have to group by, is there a shortcut similar to what you can do in a DATA step with setting up an ARRAY but with the numeric representation instead of the column names.&lt;BR /&gt;
&lt;BR /&gt;
I'm sure that there is probably a more SAS friendly way (i.e. non PROC SQL) to do what I'm trying to do however PROC SQL is really the only way to do COUNT(DISTINCT column) in a semi-efficient manner.&lt;BR /&gt;
&lt;BR /&gt;
My guess is that I'm probably just going to have to continue typing everything out, but I figured I'd ask the question.  If you never ask, you'll never truely know.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Mon, 30 Mar 2009 14:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-GROUP-BY-question/m-p/12762#M1741</guid>
      <dc:creator>daveryBBW</dc:creator>
      <dc:date>2009-03-30T14:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ... GROUP BY question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-GROUP-BY-question/m-p/12763#M1742</link>
      <description>Not sure about the sql shortcut but you could write a little bit of macro to write the code for you. Something like:&lt;BR /&gt;
&lt;BR /&gt;
%do i=1 %to 9; &lt;BR /&gt;
col&amp;amp;i.,&lt;BR /&gt;
%end;&lt;BR /&gt;
col10</description>
      <pubDate>Mon, 30 Mar 2009 15:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-GROUP-BY-question/m-p/12763#M1742</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-30T15:09:02Z</dc:date>
    </item>
  </channel>
</rss>

