<?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: Sum a column - Stop and Restart when a certain value is achieved in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881147#M348176</link>
    <description>&lt;P&gt;THANK YOU!!&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2023 16:26:35 GMT</pubDate>
    <dc:creator>CHELS</dc:creator>
    <dc:date>2023-06-16T16:26:35Z</dc:date>
    <item>
      <title>Sum a column - Stop and Restart when a certain value is achieved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881007#M348126</link>
      <description>&lt;P&gt;I have a data that looks like this:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl66" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="border-left: none; width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;3&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;4&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt; border-top: none;"&gt;5&lt;/TD&gt;
&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;6&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;7&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl68" style="height: 15.0pt; border-top: none;"&gt;8&lt;/TD&gt;
&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;9&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl67" style="height: 15.0pt; border-top: none;"&gt;10&lt;/TD&gt;
&lt;TD class="xl67" style="border-top: none; border-left: none;"&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to sum up 'Count' starting from the first row.&amp;nbsp; As soon as the Sum &amp;gt;= 20, the process starts over. Something looks like this:&lt;/P&gt;
&lt;TABLE width="189px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;ID&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;Count&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;Sum&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;12&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;18&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;6&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;7&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;8&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;11&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="62.5156px" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="62.8281px" height="30px"&gt;7&lt;/TD&gt;
&lt;TD width="62.6562px" height="30px"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 20:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881007#M348126</guid>
      <dc:creator>CHELS</dc:creator>
      <dc:date>2023-06-15T20:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sum a column - Stop and Restart when a certain value is achieved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881008#M348127</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if sum&amp;gt;=20 then sum=0;
    sum+count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 20:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881008#M348127</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-15T20:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sum a column - Stop and Restart when a certain value is achieved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881009#M348128</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data have;
  input ID 	Count;
datalines;
1 	3
2 	1
3 	2
4 	12
5 	3
6 	2
7 	9
8 	11
9 	3
10 	7
;

data want;
   set have;
   retain runningsum;
   runningsum+count;
   output;
   if runningsum ge 20 then runningsum=0;
run;&lt;/PRE&gt;
&lt;P&gt;Please note the use of a data step to provide example data. It avoids us having to ask lots of questions in some cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Retain names a variable that will hold the&amp;nbsp; value of a variable across iterations of the data step.&lt;/P&gt;
&lt;P&gt;The "trick" here is to output the values and if you have written one greater than or equal to your target set it to 0 afterwards before used in the next total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't like using variable names like Sum, which happens to be function, as it may confuse code and doesn't say anything about the sum of what.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 20:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881009#M348128</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-06-15T20:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sum a column - Stop and Restart when a certain value is achieved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881147#M348176</link>
      <description>&lt;P&gt;THANK YOU!!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 16:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-a-column-Stop-and-Restart-when-a-certain-value-is-achieved/m-p/881147#M348176</guid>
      <dc:creator>CHELS</dc:creator>
      <dc:date>2023-06-16T16:26:35Z</dc:date>
    </item>
  </channel>
</rss>

