<?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: An Advanced SAS program designed by a scientist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432470#M107120</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;

    class patient date;

    var res;

    output out=want sum=;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2018 19:47:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-01-30T19:47:31Z</dc:date>
    <item>
      <title>sum to reset to zero when encountering a new date (by subject)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432467#M107118</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi!&amp;nbsp; I'm having issues summing by&amp;nbsp;subject&amp;nbsp;&amp;nbsp;and date.&amp;nbsp; I need the sum to reset to zero when encountering a new date (by subject).&amp;nbsp; Here is my code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set&amp;nbsp;have;&lt;BR /&gt;by patient date;&lt;/P&gt;
&lt;P&gt;if first.patient and res ^= . then targetsum=res;&lt;/P&gt;
&lt;P&gt;else if res ^= . then targetsum+res;&lt;BR /&gt; output;&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here a sample of output for one subject. you can see the totals are not resetting with new date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;02OCT2017 81 81 &lt;BR /&gt;02OCT2017 22 103&lt;/P&gt;
&lt;P&gt;02OCT2017 39 142&lt;/P&gt;
&lt;P&gt;11DEC2017 93 235 &lt;BR /&gt;11DEC2017 23 258 &lt;BR /&gt;11DEC2017 57 315&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432467#M107118</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-01-30T19:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: An Advanced SAS program designed by a scientist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432470#M107120</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;

    class patient date;

    var res;

    output out=want sum=;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432470#M107120</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-01-30T19:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: sum to reset to zero when encountering a new date (by subject)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432471#M107121</link>
      <description>&lt;P&gt;As indicated, don't use a data step, use a PROC designed to summarize the data.&lt;/P&gt;
&lt;P&gt;If you need other variables included, look at PROC SUMMARY which can support adding in other variables in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432471#M107121</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T19:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: sum to reset to zero when encountering a new date (by subject)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432474#M107124</link>
      <description>&lt;P&gt;It's not clear that PROC SUMMARY does what you need.&amp;nbsp; It will get you the total for each subject/date, but it will not give you a "running total" for all observations so far.&amp;nbsp; Here is how you would modify your DATA step to do that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by patient date;&lt;/P&gt;
&lt;P&gt;if first.date then targetsum=0;&lt;/P&gt;
&lt;P&gt;targetsum + res;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 19:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-to-reset-to-zero-when-encountering-a-new-date-by-subject/m-p/432474#M107124</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-30T19:56:52Z</dc:date>
    </item>
  </channel>
</rss>

