<?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: Applying SAS function by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842759#M333236</link>
    <description>&lt;P&gt;What defines your "by group"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which "function" is to be applied? On what values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many processes may involve additional steps such a basic data set, possibly as created here and then a follow up to do group processing.&lt;/P&gt;</description>
    <pubDate>Sun, 06 Nov 2022 15:51:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-11-06T15:51:53Z</dc:date>
    <item>
      <title>Applying SAS function by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842749#M333230</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you all have a good weekend!&lt;/P&gt;&lt;P&gt;I am using the following code to compute statistics that I need:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;if _N_ = 1 then do;&lt;BR /&gt;dcl hash h(multidata : "Y", ordered : "Y");&lt;BR /&gt;h.definekey("d", "t");&lt;BR /&gt;h.definedata("d", "t", "v", "p");&lt;BR /&gt;h.definedone();&lt;BR /&gt;dcl hiter hi("h");&lt;BR /&gt;&lt;BR /&gt;dcl hash hh();&lt;BR /&gt;hh.definekey("d", "t");&lt;BR /&gt;hh.definedata("s");&lt;BR /&gt;hh.definedone();&lt;BR /&gt;&lt;BR /&gt;do until (z);&lt;BR /&gt;set have end = z;&lt;BR /&gt;h.add(key : date, key : time, data : date, data : time, data : volume, data : price);&lt;BR /&gt;if hh.find(key : date, key : Time) ne 0 then s = volume;&lt;BR /&gt;else s + volume;* will be used to compute vol-weig price ;&lt;BR /&gt;hh.replace(key : date, key : Time, data : s);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;set have;&lt;BR /&gt;d = .; t = .; v = .; p = .; s = .;&lt;BR /&gt;&lt;BR /&gt;if h.find(key : Date, key : Time + 10) = 0 then mt = t;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;else do;&lt;BR /&gt;rc = hi.setcur(key : Date, key : Time);&lt;BR /&gt;do i = 1 by 1 while(hi.next() = 0 &amp;amp; Date = d);&lt;BR /&gt;if t - time &amp;gt; 10 then do;&lt;BR /&gt;if i = 1 then mt = .;&lt;BR /&gt;leave;&lt;BR /&gt;end;&lt;BR /&gt;if t &amp;gt; time then mt = t;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;rc = hh.find(key: date, key : mt);&lt;BR /&gt;rc = h.reset_dup();&lt;BR /&gt;&lt;BR /&gt;do while (h.do_over(key : date, key : mt) = 0);&lt;BR /&gt;pp = sum(pp, divide(v, s) * p);&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;dif = (log(price) - log(pp))*10000; *bps;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The issue is I need to apply this function by group. Is there an easy way of doing this?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 14:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842749#M333230</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2022-11-06T14:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Applying SAS function by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842759#M333236</link>
      <description>&lt;P&gt;What defines your "by group"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which "function" is to be applied? On what values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many processes may involve additional steps such a basic data set, possibly as created here and then a follow up to do group processing.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 15:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842759#M333236</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-06T15:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Applying SAS function by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842760#M333237</link>
      <description>&lt;P&gt;Sorry,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I should define the question better. I found a way. Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 15:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842760#M333237</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2022-11-06T15:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Applying SAS function by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842761#M333238</link>
      <description>&lt;P&gt;Why use hash objects here, for what seems like simple arithmetic and cumulative totals? All of that is done easily in a DATA step without resorting to hash objects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
    by sex;
run;
data want;
    set class;
    by sex;
    if first.sex then cumulative_height=0;
    cumulative_height+height;
run;&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;Whatever the exact function you are trying to get can be easily incorporated into this method.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2022 16:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-SAS-function-by-group/m-p/842761#M333238</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-06T16:00:51Z</dc:date>
    </item>
  </channel>
</rss>

