<?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 , select with different vars list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756401#M238797</link>
    <description>Thanks.&lt;BR /&gt;I expected that in the result of this code we we will see Ids(field ACCT) that appear in more than 1 row and each id will have one row .&lt;BR /&gt;Actually in the rssults i see that if id has 2 rows in source data then in the resulted data will have also 2 rows...&lt;BR /&gt;May i ask why???&lt;BR /&gt;&lt;BR /&gt;SELECT ACCT, FNAME, LNAME, STATE, PHONE, STATUS,&lt;BR /&gt;count(*) as nr&lt;BR /&gt;FROM ACCTDAT&lt;BR /&gt;GROUP BY ACCT&lt;BR /&gt;HAVING NUMACCT GE 2;&lt;BR /&gt;quit;</description>
    <pubDate>Sat, 24 Jul 2021 10:53:26 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-07-24T10:53:26Z</dc:date>
    <item>
      <title>group by , select with different vars list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756396#M238793</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;A far as I know in the sql original langauge&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"Any column in SELECT clause that are not used by aggregate function (SUM, MIN, etc) needs to be listed in the&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;GROUP BY&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;clause."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; 
SELECT &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;ACCT&lt;/FONT&gt; &lt;/STRONG&gt;,
       count(*) as nr
 FROM ACCTDAT
 GROUP BY &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ACCT&lt;/STRONG&gt;&lt;/FONT&gt;
 HAVING NUMACCT GE 2;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I saw another code where the list of varaibles in SELECT are different then the list of varaibles in group BY&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; 
SELECT &lt;FONT color="#FF0000"&gt;ACCT, FNAME, LNAME, STATE, PHONE, STATUS&lt;/FONT&gt;, 
 count(*) as nr
 FROM ACCTDAT
 GROUP BY &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;ACCT&lt;/FONT&gt;&lt;/STRONG&gt;
 HAVING NUMACCT GE 2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;May anyone explain the difference?&lt;/P&gt;
&lt;P&gt;How is it called?&amp;nbsp;(Is it called re-merge??)&lt;/P&gt;
&lt;P&gt;MAy anyone send&amp;nbsp; link to read about it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;P&gt;Here is the data set:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ACCT FNAME LNAME STATE PHONE STATUS
00001 KYLE RANGER FL 941-555-1234 TEST
12345 AMBER ERICKSON MN 507-012-3456 TEST
33333 ALICE ANDERSON FL 941-555-1236 CNTL
44455 HOWARD SMITH GA 706-555-0001 TEST
55666 GEORGE WILLIAMS GA 706-555-0002 CNTL
66777 NANCY BECK GA 706-555-0003 CNTL
67890 JOAN HALLEY WI 608-001-2345 TEST
76543 HEATHER SAMPSON FL 941-555-1235 TEST
77788 MARIA ALVAREZ TX 817-003-4567 TEST
88899 TINA HOLT OR 503-004-5678 CNTL
98765 KEVIN TRACEN TX 817-098-7654 TEST
99900 WALTER DENNIS MN 612-009-2345 TEST&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 08:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756396#M238793</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-24T08:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: group by , select with different vars list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756399#M238796</link>
      <description>&lt;P&gt;You are perfectly right, when not all variables which are not the subject of a summary function are listed in the GROUP BY, SAS will perform a remerge and write a NOTE about that to the log. This is different from most (if not all) other SQL flavors. Other SQL flavors will need a sub-select to create the same result.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 10:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756399#M238796</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-24T10:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: group by , select with different vars list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756401#M238797</link>
      <description>Thanks.&lt;BR /&gt;I expected that in the result of this code we we will see Ids(field ACCT) that appear in more than 1 row and each id will have one row .&lt;BR /&gt;Actually in the rssults i see that if id has 2 rows in source data then in the resulted data will have also 2 rows...&lt;BR /&gt;May i ask why???&lt;BR /&gt;&lt;BR /&gt;SELECT ACCT, FNAME, LNAME, STATE, PHONE, STATUS,&lt;BR /&gt;count(*) as nr&lt;BR /&gt;FROM ACCTDAT&lt;BR /&gt;GROUP BY ACCT&lt;BR /&gt;HAVING NUMACCT GE 2;&lt;BR /&gt;quit;</description>
      <pubDate>Sat, 24 Jul 2021 10:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756401#M238797</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-07-24T10:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: group by , select with different vars list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756403#M238799</link>
      <description>&lt;P&gt;Since the variable you GROUP BY (ACCT) is unique in your example data, the remerge will be noted, but have no effect.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 11:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-select-with-different-vars-list/m-p/756403#M238799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-24T11:01:02Z</dc:date>
    </item>
  </channel>
</rss>

