<?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 sum up rows and divide till it reach a specific value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800484#M314919</link>
    <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following problem, I would like to sum up a column and divide the sum every line through the sum of the whole column till a specific value is reached. so in Pseudocode it would look like that:&lt;/P&gt;&lt;P&gt;data;&lt;/P&gt;&lt;P&gt;sum_of_whole_column = sum(column);&lt;/P&gt;&lt;P&gt;subtotal[i] = 0;&lt;/P&gt;&lt;P&gt;i =1;&lt;/P&gt;&lt;P&gt;do until (subtotal[i] = 70000)&lt;/P&gt;&lt;P&gt;subtotal[i] = (subtotal[i] + subtotal[i+1])/sum_of_whole_column&lt;/P&gt;&lt;P&gt;i = i+1&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I don't know if the Syntax is right, can I use that subtotal[i] to get the value in a specific cell? so I would like to run through an existing column...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I get the error that I haven't defined an array... so can I use something else instead of subtotal[i]?&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2022 17:53:36 GMT</pubDate>
    <dc:creator>newbie69</dc:creator>
    <dc:date>2022-03-06T17:53:36Z</dc:date>
    <item>
      <title>sum up rows and divide till it reach a specific value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800484#M314919</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following problem, I would like to sum up a column and divide the sum every line through the sum of the whole column till a specific value is reached. so in Pseudocode it would look like that:&lt;/P&gt;&lt;P&gt;data;&lt;/P&gt;&lt;P&gt;sum_of_whole_column = sum(column);&lt;/P&gt;&lt;P&gt;subtotal[i] = 0;&lt;/P&gt;&lt;P&gt;i =1;&lt;/P&gt;&lt;P&gt;do until (subtotal[i] = 70000)&lt;/P&gt;&lt;P&gt;subtotal[i] = (subtotal[i] + subtotal[i+1])/sum_of_whole_column&lt;/P&gt;&lt;P&gt;i = i+1&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but I don't know if the Syntax is right, can I use that subtotal[i] to get the value in a specific cell? so I would like to run through an existing column...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: I get the error that I haven't defined an array... so can I use something else instead of subtotal[i]?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 17:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800484#M314919</guid>
      <dc:creator>newbie69</dc:creator>
      <dc:date>2022-03-06T17:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: sum up rows and divide till it reach a specific value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800492#M314922</link>
      <description>&lt;P&gt;Syntax is not right, I can fix that. You did not define an array, and you don't need an array here. Arrays let you do things across different columns, which you don't seem to have here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your logic may not be right, I have no idea what you want. When you divide a value in a column by the sum of a column, the result cannot be 70000. The result is a percent (I guess if you have HUGE positive and negative numbers, maybe you can get 70000, but otherwise not)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    var column;
    output out=sum sum=sum_of_whole_column;
run;
data want;
    if _n_=1 then set sum;
    set have;
    subtotal + column; /* Cumulative sum */
    cumulative_percent=subtotal / sum_of_whole_column;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From there, you can delete whatever you want until you get the desired cumulative percent.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 19:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800492#M314922</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-06T19:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: sum up rows and divide till it reach a specific value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800493#M314923</link>
      <description>&lt;P&gt;hey, first of all thank you very much, that's exactly what I need! The only thing that I also want is that it stop if I reach a specific percentage, that's the reason why I used that "do until", so I want to stop the process when the percentage is for example 70%. thanks and best regards&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 19:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800493#M314923</guid>
      <dc:creator>newbie69</dc:creator>
      <dc:date>2022-03-06T19:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: sum up rows and divide till it reach a specific value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800498#M314927</link>
      <description>&lt;P&gt;you can modify DATA WANT as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    if _n_=1 then set sum;
    set have;
    subtotal + column; /* Cumulative sum */
    cumulative_percent=subtotal / sum_of_whole_column;
    if cumulative_percent &amp;gt; 0.7 then stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As noted before, I don't know what will happen if there are both negative and positive numbers in variable COLUMN, then the logic above probably needs to be modified (or maybe its fine the way it is).&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 20:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-up-rows-and-divide-till-it-reach-a-specific-value/m-p/800498#M314927</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-06T20:18:42Z</dc:date>
    </item>
  </channel>
</rss>

