<?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: proc sql, counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517174#M139760</link>
    <description>&lt;P&gt;Alternatively look at proc means, summary or just a one pass of the datastep to have better control of the order&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Nov 2018 17:57:38 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-29T17:57:38Z</dc:date>
    <item>
      <title>proc sql, counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517162#M139751</link>
      <description>&lt;P&gt;When I use this code:&lt;/P&gt;
&lt;P&gt;proc sql; create table finn_counts1 as select *, sum(finn36) as ct_finn36 from finn1 &lt;BR /&gt;group by ACCOUNT_ID; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the correct sum (albeit it's for each row of&amp;nbsp;&lt;SPAN&gt;ACCOUNT_ID, and I can dedup that) but why does the order of the rows for each&amp;nbsp;ACCOUNT_ID change? It's not sorted by any variable, looks randomly changed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Get these notes in the log:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: The query requires remerging summary statistics back with the original&lt;BR /&gt; data.&lt;BR /&gt;NOTE: SAS threaded sort was used.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do I need to sort the data again to keep the original sequence per&amp;nbsp;ACCOUNT_ID&amp;nbsp;?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 17:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517162#M139751</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2018-11-29T17:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517173#M139759</link>
      <description>&lt;P&gt;add on order by&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;order by account_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you had used -&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table finn_counts1 as
 select ACCOUNT_ID, sum(finn36) as ct_finn36
from finn1 
group by ACCOUNT_ID
order by ACCOUNT_ID;
 quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Proc sql wouldn't have remerged but I am assuming you perhaps want other variables besides the sum&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 17:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517173#M139759</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-29T17:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517174#M139760</link>
      <description>&lt;P&gt;Alternatively look at proc means, summary or just a one pass of the datastep to have better control of the order&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 17:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517174#M139760</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-29T17:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517175#M139761</link>
      <description>&lt;P&gt;run both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Intially dataset is ordersed by name. Once you want to group by sex all same gender are sorted so that summing of same becomes easy. this is part of underhood mechanism which you can understand by using _method&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select * from sashelp.class;


proc sql;
create table want1 as 
select *, sum(age) from sashelp.class
group by sex;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* then run _method*/


proc sql _method;
create table want1 as 
select *, sum(age) from sashelp.class
group by sex;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;_method gives the following in log explaining how a group by is conducted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sqxcrta
sqxsumg
sqxsort
sqxsrc( SASHELP.CLASS )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;now the sort happens&amp;nbsp; on gender as per the _method.&lt;/P&gt;
&lt;P&gt;sqxceta -- creating final dataset&lt;/P&gt;
&lt;P&gt;sqxsumg - sum within group&lt;/P&gt;
&lt;P&gt;sqxsort-- sorting( done on your group by variable)&lt;/P&gt;
&lt;P&gt;sqxsrc -source table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To havefinal dataset as per you please try using&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;suggestion. Then dataset will be reordered as per your needs&lt;/P&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 29 Nov 2018 18:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517175#M139761</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-29T18:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql, counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517180#M139765</link>
      <description>&lt;P&gt;Wow...thanks...learnt something new!&lt;BR /&gt;Yes, I ended up ordering by ACCOUNT_ID and some other variables.&lt;BR /&gt;Thanks to both of you ,&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 18:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-counts/m-p/517180#M139765</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2018-11-29T18:13:32Z</dc:date>
    </item>
  </channel>
</rss>

