<?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 on a created variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745234#M233570</link>
    <description>&lt;P&gt;You need to include strtdate and enddate in the GROUP BY clause, otherwise you get the automatic remerge (which is also NOTEd in the log - Maxim 2!)&lt;/P&gt;</description>
    <pubDate>Wed, 02 Jun 2021 16:15:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-02T16:15:50Z</dc:date>
    <item>
      <title>Group by on a created variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745233#M233569</link>
      <description>&lt;P&gt;Trying the following code and it is not producing the results I expect. I am assuming it's because I'm using a defined variable in the sql in my group by statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data user.step_one;                                    
 length acct $10 strtdate $ 9 enddate $ 9 dsname $64;  
 input acct $ strtdate $ enddate $ size dsname $;      
 cards;                                                
  7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.ONE   
  7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.TWO   
  7733K772U1 01JUN2021 01JUN2021 100 KKSO01.TEST.ONE   
  7733K772U1 01JUN2021 01JUN2021 100 KJDY01.TEST.THREE 
  7733K772U1 01JUN2021 01JUN2021 100 KRRB01.TEST.ONE   
  7733K772U1 01JUN2021 01JUN2021 100 KRRB01.TEST.TWO   
  7733K772U1 01JUN2021 01JUN2021 100 KKSO01.TEST.TWO   
  7733K772U1 01JUN2021 01JUN2021 100 KRDO01.TEST.ONE   
run;                                                   
                                                       
proc sql;                                              
  select acct, strtdate, enddate, sum(size),           
         scan(dsname,1,'.') as hlq label='hlq'         
    from user.step_one                                 
    group by hlq, acct;                                &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I expect just four lines of output with the summed size variable. I will try and run my summarization in another step and build the table with this code. Just curious.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 16:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745233#M233569</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2021-06-02T16:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Group by on a created variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745234#M233570</link>
      <description>&lt;P&gt;You need to include strtdate and enddate in the GROUP BY clause, otherwise you get the automatic remerge (which is also NOTEd in the log - Maxim 2!)&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 16:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745234#M233570</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-02T16:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Group by on a created variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745251#M233574</link>
      <description>&lt;P&gt;Thank you sir. That does what I expect. I changed one of my acct numbers and further tested the group by and we are off and running. I'm not sure I quite understand that logic but looks like I have some reading to do. Thank you for referencing the efficient programmer link.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 17:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745251#M233574</guid>
      <dc:creator>G_I_Jeff</dc:creator>
      <dc:date>2021-06-02T17:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Group by on a created variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745293#M233589</link>
      <description>&lt;P&gt;When youbdo GROUP BY in SQL, any item in the SELECT must either be&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a constant&lt;/LI&gt;
&lt;LI&gt;part of a summary function&lt;/LI&gt;
&lt;LI&gt;or in the GROUP BY&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If a variable that is not part of GROUP BY appears in the SELECT, other SQL flavors will throw an error, but SAS will do an automatic remerge which results in all observations being kept, and put a corresponding NOTE in the log.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 19:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-on-a-created-variable/m-p/745293#M233589</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-02T19:15:32Z</dc:date>
    </item>
  </channel>
</rss>

