<?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: Aggregate data by group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84412#M24185</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a question...&lt;/P&gt;&lt;P&gt;Why the upper half is taking &lt;STRONG&gt;only the last occurance number&lt;/STRONG&gt;.......&lt;/P&gt;&lt;P&gt;whereas&amp;nbsp; the lower half of the code is taking all the counts even though we said do until(last.id) for both of them??&lt;/P&gt;&lt;P&gt;IS IT THE OUTPUT STATEMENT WHICH IS MAKING THE DIFFERENCE FOR THE BOTTOM HALF ALONE TO DISPLAY THE 1,2,3 instead of just 3!!1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Mar 2013 18:47:34 GMT</pubDate>
    <dc:creator>robertrao</dc:creator>
    <dc:date>2013-03-22T18:47:34Z</dc:date>
    <item>
      <title>Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84407#M24180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to ask if I could achieve from A to B in just one single datastep instead of what I've done below( a datastep and sql)?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Thank you very much.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data A; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set tmp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; n+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.idthen n=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table B as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *, count(id) as total&lt;/P&gt;&lt;P&gt;&amp;nbsp; from A&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A:&lt;/P&gt;&lt;P&gt;id val n&lt;/P&gt;&lt;P&gt;1 11 1&lt;/P&gt;&lt;P&gt;1 22 2&lt;/P&gt;&lt;P&gt;1 33 3&lt;/P&gt;&lt;P&gt;2 22 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B:&lt;/P&gt;&lt;P&gt;id val n total&lt;/P&gt;&lt;P&gt;1 11 1&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1 22 2&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1 33 3&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2 22 1&amp;nbsp; 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 07:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84407#M24180</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2013-03-21T07:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84408#M24181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can't really see that you could, maybe using some advanced read-ahead programming, or using hash objects.&lt;/P&gt;&lt;P&gt;But why, is there a real problem, or optimizing for fun?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 08:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84408#M24181</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-03-21T08:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84409#M24182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Linus. Thanks for your prompt reply.&lt;/P&gt;&lt;P&gt;I'm just wondering may be there are other more elegant coding ways to achieve this than what I did. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 09:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84409#M24182</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2013-03-21T09:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84410#M24183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, you can in a way.&amp;nbsp; You still have to read the data twice, but you can accomplish that in a single DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data B;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; n=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; total=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set A (keep=id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set A;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each SET statement reads the entire data set independently of the other SET statement.&amp;nbsp; So for each ID, the top loop counts the number of records, and the bottom loop reads the same records, calculates N, and outputs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 13:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84410#M24183</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-03-21T13:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84411#M24184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Astounding.&lt;/P&gt;&lt;P&gt;Thanks for your input.&lt;BR /&gt;It's always great to know other coding ways. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 23:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84411#M24184</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2013-03-21T23:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84412#M24185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a question...&lt;/P&gt;&lt;P&gt;Why the upper half is taking &lt;STRONG&gt;only the last occurance number&lt;/STRONG&gt;.......&lt;/P&gt;&lt;P&gt;whereas&amp;nbsp; the lower half of the code is taking all the counts even though we said do until(last.id) for both of them??&lt;/P&gt;&lt;P&gt;IS IT THE OUTPUT STATEMENT WHICH IS MAKING THE DIFFERENCE FOR THE BOTTOM HALF ALONE TO DISPLAY THE 1,2,3 instead of just 3!!1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Mar 2013 18:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84412#M24185</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-03-22T18:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84413#M24186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It probably takes more than a brief post to explain the whole nine yard. The structure that Astounding used is call DOW, there are lots of histories around it. Google SAS DOW, you will know. &lt;/P&gt;&lt;P&gt;Here is one paper by Dorfman, who participated this part of history:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings09/038-2009.pdf" title="http://support.sas.com/resources/papers/proceedings09/038-2009.pdf"&gt;http://support.sas.com/resources/papers/proceedings09/038-2009.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Mar 2013 19:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84413#M24186</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-03-22T19:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84414#M24187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Although it appears that the data set is read twice, working with a BY statement, it is probable that the required buffers or pages of the data set, will be in memory when the second SET is performed - so unless BY groups are very large, performance is unlikely to be affected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 18:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84414#M24187</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-03-23T18:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84415#M24188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;robertrao&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read the paper offered by Haikuo&amp;nbsp;&amp;nbsp; to find the explanation.&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/resources/papers/proceedings09/038-2009.pdf"&gt;http://support.sas.com/resources/papers/proceedings09/038-2009.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 18:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84415#M24188</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-03-23T18:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84416#M24189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;so after SAS loops through the 1st by group it moves to the second loop,right,is that how DOWs work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 22:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84416#M24189</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-03-23T22:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84417#M24190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes!&amp;nbsp; Then, at the end of the last loop, it goes back to the beginning to get the next level of the by variable(s).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 22:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84417#M24190</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-03-23T22:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84418#M24191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what you describe is the way this program works ("after SAS loops through the 1st by group it moves to the second loop")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general, DoW loops place a DO loop around a SET statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The program here is more complex, having two interrelated DoW loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;peterC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 23:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84418#M24191</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-03-23T23:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate data by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84419#M24192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks guys&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Mar 2013 00:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Aggregate-data-by-group/m-p/84419#M24192</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-03-24T00:20:40Z</dc:date>
    </item>
  </channel>
</rss>

