<?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: How to create the counting number with accumulative volume in the dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/747662#M234711</link>
    <description>&lt;P&gt;I think you can do it if you retain the total and the difference.&lt;/P&gt;
&lt;P&gt;Also, please post your data in a form that can be used for data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input obs Item Volume;
datalines;
1        1         400
2        1       1000
3        1       1500
4        1        300
101    2         5500
102    2        1300
103    2         600
;
run;

data want;
  set have;
  by item;
  retain accum dif box;
  if first.item then do;
    Accum=0;
    box=1;
  end;
  Accum=sum(Volume,Accum);
  do until(Accum&amp;lt;2000);
    if Accum&amp;gt;2000 then do;
      dif=Accum-2000;
      Accum=2000;
      output;
      Volume=.;
      Accum=dif;
      box+1;
      if Accum&amp;lt;2000 then output;
    end;else
    do;
      output;
    end;
  end;
  drop dif;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 14 Jun 2021 00:36:10 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-06-14T00:36:10Z</dc:date>
    <item>
      <title>How to create the counting number with accumulative volume in the dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/747525#M234628</link>
      <description>&lt;P&gt;My question is that I want to compute the following situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are sale volume from customers which can vary in size. Each sale volume will be put into a box but the box size is fixed. If the volume is smaller, more than one sale orders can fill in the same box. If it's larger it will fit in several boxes until the over-size amount is gone. The problem is that how can I create the box number which can be counted continuously.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume that the size of each box is 2000.&amp;nbsp; The sample data looks like this.&lt;/P&gt;&lt;P&gt;#Case 1: Volume is smaller than box size&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Arriving Volume&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Volume filled in each box&lt;/TD&gt;&lt;TD&gt;Accum Volume&lt;/TD&gt;&lt;TD&gt;Box Number&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;TD&gt;400&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;1400&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1500&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;TD&gt;900&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;1200&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;....&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Case 2: Volume is larger than box size&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Arriving Volume&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Volume filled in each box&lt;/TD&gt;&lt;TD&gt;Accum Volume&lt;/TD&gt;&lt;TD&gt;Box Number&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5500&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1500&lt;/TD&gt;&lt;TD&gt;1500&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1300&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;1400&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;..&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I have is just the arriving volume (1st colume) and the box size. Each item will be treated separately.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;I have this:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Obs&amp;nbsp; &amp;nbsp; Item&amp;nbsp; Volume&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 300&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5500&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1300&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;600&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want this.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Obs&amp;nbsp; &amp;nbsp; Item&amp;nbsp; Volume&amp;nbsp; Accum&amp;nbsp; Box#&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;400&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 400&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1400&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;lt;= 600 in box#1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 900&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;= 900 in box#2&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1200&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;lt;=&amp;nbsp;fill up several boxes&amp;nbsp;&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;= remaining portion in box#3&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;lt;= fill up with 500&lt;/P&gt;&lt;P&gt;105&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;800&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;lt;= remaining in box#4&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;600&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1400&amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attempt to create the accumulated volume in a box but it cannot handle the data correctly, especially in the second case. I cannot insert additional rows in the table and keep on counting the number of box correctly.&lt;/P&gt;&lt;P&gt;Could anyone kindly suggest how to handle this problem please? Your answer is very much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jun 2021 14:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/747525#M234628</guid>
      <dc:creator>ta_na_ka</dc:creator>
      <dc:date>2021-06-13T14:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the counting number with accumulative volume in the dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/747662#M234711</link>
      <description>&lt;P&gt;I think you can do it if you retain the total and the difference.&lt;/P&gt;
&lt;P&gt;Also, please post your data in a form that can be used for data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input obs Item Volume;
datalines;
1        1         400
2        1       1000
3        1       1500
4        1        300
101    2         5500
102    2        1300
103    2         600
;
run;

data want;
  set have;
  by item;
  retain accum dif box;
  if first.item then do;
    Accum=0;
    box=1;
  end;
  Accum=sum(Volume,Accum);
  do until(Accum&amp;lt;2000);
    if Accum&amp;gt;2000 then do;
      dif=Accum-2000;
      Accum=2000;
      output;
      Volume=.;
      Accum=dif;
      box+1;
      if Accum&amp;lt;2000 then output;
    end;else
    do;
      output;
    end;
  end;
  drop dif;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Jun 2021 00:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/747662#M234711</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-06-14T00:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create the counting number with accumulative volume in the dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/748633#M235121</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your suggestion. It works perfectly as needed. I am sorry for an inconvenience caused with the dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 08:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-the-counting-number-with-accumulative-volume-in/m-p/748633#M235121</guid>
      <dc:creator>ta_na_ka</dc:creator>
      <dc:date>2021-06-17T08:04:37Z</dc:date>
    </item>
  </channel>
</rss>

