<?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: Find date when cumulative sum is above threshold in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799369#M314317</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain found;
by id date;
if first.id then do ;cum_days = days; found=0; end;
else cum_days + days;

if cum_days &amp;gt; 30 and found = 0 then do;
found=1;
output;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add another flag variable to check if the value was already output and use RETAIN to keep it the same across rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58661"&gt;@nmp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to get the date when a cumulative sum exceeds a threshold (30 days here) by group, and only that row. I know I can add a cumulative sum output all the rows with &amp;gt; 30 and then sort and keep only the first row. But I am trying see if there is a way to do it in a single step.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date days ;&lt;BR /&gt;cards;&lt;BR /&gt;1 02DEC2014 3&lt;BR /&gt;1 01JAN2015 15&lt;BR /&gt;1 15JAN2015 15&lt;BR /&gt;2 02JAN2015 30&lt;BR /&gt;2 02FEB2015 30&lt;BR /&gt;2 01MAR2015 30&lt;BR /&gt;2 02APR2015 30&lt;BR /&gt;3 16DEC2014 3&lt;BR /&gt;3 30DEC2014 3&lt;BR /&gt;3 01JAN2015 3&lt;BR /&gt;3 16JAN2015 3&lt;BR /&gt;3 30JAN2015 3&lt;BR /&gt;3 01FEB2015 3&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;WANT:&lt;/P&gt;
&lt;P&gt;1 15JAN2015&lt;BR /&gt;2 02FEB2015&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FYI - please test the code you post runs correctly, your posted code did not run correctly for me.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2022 16:28:31 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-03-01T16:28:31Z</dc:date>
    <item>
      <title>Find date when cumulative sum is above threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799357#M314308</link>
      <description>&lt;P&gt;I am trying to get the date when a cumulative sum exceeds a threshold (30 days here) by group, and only that row. I know I can add a cumulative sum output all the rows with &amp;gt; 30 and then sort and keep only the first row. But I am trying see if there is a way to do it in a single step.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date days ;&lt;BR /&gt;cards;&lt;BR /&gt;1 02DEC2014 3&lt;BR /&gt;1 01JAN2015 15&lt;BR /&gt;1 15JAN2015 15&lt;BR /&gt;2 02JAN2015 30&lt;BR /&gt;2 02FEB2015 30&lt;BR /&gt;2 01MAR2015 30&lt;BR /&gt;2 02APR2015 30&lt;BR /&gt;3 16DEC2014 3&lt;BR /&gt;3 30DEC2014 3&lt;BR /&gt;3 01JAN2015 3&lt;BR /&gt;3 16JAN2015 3&lt;BR /&gt;3 30JAN2015 3&lt;BR /&gt;3 01FEB2015 3&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;WANT:&lt;/P&gt;&lt;P&gt;1 15JAN2015&lt;BR /&gt;2 02FEB2015&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799357#M314308</guid>
      <dc:creator>nmp</dc:creator>
      <dc:date>2022-03-01T16:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find date when cumulative sum is above threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799364#M314312</link>
      <description>&lt;P&gt;Why does the WANT data set have only those two rows?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799364#M314312</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-01T16:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find date when cumulative sum is above threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799368#M314316</link>
      <description>&lt;P&gt;Sorry, I just realized that my have data set may not have been clear. The days in the data set are not cumulative, so if I create a cumulative total it would look like the one below. The want data set has the dates when each person first had &amp;gt; 30 days. 1 has 33 on 15Jan2015, person 2 has 60 on 02Feb2015 and person 3 never has &amp;gt; 30, so doesn't show up in want.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id visitdt days totdays;&lt;BR /&gt;cards;&lt;BR /&gt;1 02DEC2014 3 3&lt;BR /&gt;1 01JAN2015 15 18&lt;BR /&gt;1 15JAN2015 15 33&lt;BR /&gt;2 02JAN2015 30 30&lt;BR /&gt;2 02FEB2015 30 60&lt;BR /&gt;2 01MAR2015 30 90&lt;BR /&gt;2 02APR2015 30 120&lt;BR /&gt;3 16DEC2014 3 3&lt;BR /&gt;3 30DEC2014 3 6&lt;BR /&gt;3 01JAN2015 3 9&lt;BR /&gt;3 16JAN2015 3 12&lt;BR /&gt;3 30JAN2015 3 15&lt;BR /&gt;3 01FEB2015 3 18&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799368#M314316</guid>
      <dc:creator>nmp</dc:creator>
      <dc:date>2022-03-01T16:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find date when cumulative sum is above threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799369#M314317</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain found;
by id date;
if first.id then do ;cum_days = days; found=0; end;
else cum_days + days;

if cum_days &amp;gt; 30 and found = 0 then do;
found=1;
output;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add another flag variable to check if the value was already output and use RETAIN to keep it the same across rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58661"&gt;@nmp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to get the date when a cumulative sum exceeds a threshold (30 days here) by group, and only that row. I know I can add a cumulative sum output all the rows with &amp;gt; 30 and then sort and keep only the first row. But I am trying see if there is a way to do it in a single step.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id date days ;&lt;BR /&gt;cards;&lt;BR /&gt;1 02DEC2014 3&lt;BR /&gt;1 01JAN2015 15&lt;BR /&gt;1 15JAN2015 15&lt;BR /&gt;2 02JAN2015 30&lt;BR /&gt;2 02FEB2015 30&lt;BR /&gt;2 01MAR2015 30&lt;BR /&gt;2 02APR2015 30&lt;BR /&gt;3 16DEC2014 3&lt;BR /&gt;3 30DEC2014 3&lt;BR /&gt;3 01JAN2015 3&lt;BR /&gt;3 16JAN2015 3&lt;BR /&gt;3 30JAN2015 3&lt;BR /&gt;3 01FEB2015 3&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;WANT:&lt;/P&gt;
&lt;P&gt;1 15JAN2015&lt;BR /&gt;2 02FEB2015&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FYI - please test the code you post runs correctly, your posted code did not run correctly for me.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799369#M314317</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-01T16:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find date when cumulative sum is above threshold</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799384#M314327</link>
      <description>&lt;P&gt;Thank you for this simple, straightforward solution.&lt;/P&gt;&lt;P&gt;I will check my code in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-date-when-cumulative-sum-is-above-threshold/m-p/799384#M314327</guid>
      <dc:creator>nmp</dc:creator>
      <dc:date>2022-03-01T16:49:31Z</dc:date>
    </item>
  </channel>
</rss>

