<?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 sum of multiple positive and negative values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792659#M253979</link>
    <description>&lt;P&gt;Ok. The first output is quite simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regaring the second output.. Do you want ALL combinations of values that equal zero when summed?&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 20:13:31 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-01-26T20:13:31Z</dc:date>
    <item>
      <title>Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792637#M253972</link>
      <description>I have an "amount" column in a dataset which has several positive and negative values. I want to create one output which has same positive and negative numbers(eg: - 56,56,-72,72) and another output(excludes the data in first output) which has total values of any combination of positive and negative numbers equals to 0. (eg:, -5,-10,15), (-90,10,-5,85).. Is it possible to do this in SAS.. Please suggest..</description>
      <pubDate>Wed, 26 Jan 2022 19:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792637#M253972</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2022-01-26T19:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792640#M253974</link>
      <description>&lt;P&gt;Can you provide some sample data and an explanation from that?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 19:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792640#M253974</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-01-26T19:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792643#M253977</link>
      <description>Sure. Please find below the sample data&lt;BR /&gt;Amount_column&lt;BR /&gt;-56&lt;BR /&gt;76&lt;BR /&gt;10&lt;BR /&gt;-76&lt;BR /&gt;56&lt;BR /&gt;20&lt;BR /&gt;-45&lt;BR /&gt;-3&lt;BR /&gt;15&lt;BR /&gt;-35&lt;BR /&gt;40&lt;BR /&gt;4&lt;BR /&gt;4&lt;BR /&gt;First output should hv&lt;BR /&gt;Amount_col&lt;BR /&gt;-56&lt;BR /&gt;56&lt;BR /&gt;76&lt;BR /&gt;-76&lt;BR /&gt;&lt;BR /&gt;Second output should have&lt;BR /&gt;Flag amount_col&lt;BR /&gt;A 10&lt;BR /&gt;A 20&lt;BR /&gt;A 15&lt;BR /&gt;A - 45&lt;BR /&gt;B 40&lt;BR /&gt;B 4&lt;BR /&gt;B 4&lt;BR /&gt;B - 45&lt;BR /&gt;B - 3&lt;BR /&gt;if you sum all A, then it will b 0 and if you sum all B, it will be 0..(offset)&lt;BR /&gt;Or even one output will be better&lt;BR /&gt;Flag amount_col&lt;BR /&gt;Zero 56&lt;BR /&gt;Zero -56&lt;BR /&gt;Zero - 76&lt;BR /&gt;Zero 76&lt;BR /&gt;A 10&lt;BR /&gt;A 20&lt;BR /&gt;A 15&lt;BR /&gt;A - 45&lt;BR /&gt;B 40&lt;BR /&gt;B 4&lt;BR /&gt;B 4&lt;BR /&gt;B - 45&lt;BR /&gt;B - 3</description>
      <pubDate>Thu, 27 Jan 2022 13:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792643#M253977</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2022-01-27T13:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792659#M253979</link>
      <description>&lt;P&gt;Ok. The first output is quite simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regaring the second output.. Do you want ALL combinations of values that equal zero when summed?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 20:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792659#M253979</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-01-26T20:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792660#M253980</link>
      <description>Yes all combinations of values(positive and negative) that equal to 0 but once we identified a set of numbers thats sum is 0,that number/row item shouldn't be used again</description>
      <pubDate>Wed, 26 Jan 2022 20:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792660#M253980</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2022-01-26T20:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792838#M254048</link>
      <description>&lt;P&gt;I think you can't get job done simply by data step code.&lt;/P&gt;
&lt;P&gt;You need SAS/OR to solve this kind of question.&lt;/P&gt;
&lt;P&gt;Post it at OR forum&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/bd-p/operations_research" target="_blank"&gt;https://communities.sas.com/t5/Mathematical-Optimization/bd-p/operations_research&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And calling out&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 13:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792838#M254048</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-27T13:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792981#M254101</link>
      <description>&lt;P&gt;The following code uses PROC OPTMODEL in SAS/OR or SAS Optimization to maximize the number of zero-sum groups:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input amount;
   datalines;
-56
76
10
-76
56
20
-45
-3
15
-35
40
4
4
;

proc optmodel;
   /* declare parameters and read input data set */
   set OBS;
   num amount {OBS};
   read data have into OBS=[_N_] amount;
   num numGroups = card(OBS)/2;
   set GROUPS = 1..numGroups;
   
   /* declare decision variables */
   var UseGroup {GROUPS} binary;
   var Assign {OBS, GROUPS} binary;

   /* declare objective */
   max NumGroupsUsed = sum {g in GROUPS} UseGroup[g];

   /* declare constraints */
   con OneGroupPerObs {i in OBS}:
      sum {g in GROUPS} Assign[i,g] &amp;lt;= 1;
   con GroupSumZero {g in GROUPS}:
      sum {i in OBS} amount[i] * Assign[i,g] = 0;
   con AssignImpliesUse {i in OBS, g in GROUPS}:
      Assign[i,g] &amp;lt;= UseGroup[g];
   con UseImpliesAssign {g in GROUPS}:
      2*UseGroup[g] &amp;lt;= sum {i in OBS} Assign[i,g];
   con Symmetry {g in GROUPS diff {1}}:
      UseGroup[g] &amp;lt;= UseGroup[g-1];

   /* call MILP solver */
   solve;

   /* create output data set */
   num assignedGroup {OBS};
   for {i in OBS} do;
      for {g in GROUPS: Assign[i,g].sol &amp;gt; 0.5} do;
         assignedGroup[i] = g;
         leave;
      end;
   end;
   create data want from [i] amount assignedGroup;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting optimal solution has 4 groups:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;i&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;amount&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;assignedGroup&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;-56&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;76&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;-76&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;TD class="r data"&gt;56&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;TD class="r data"&gt;-45&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="r data"&gt;-3&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="r data"&gt;9&lt;/TD&gt;
&lt;TD class="r data"&gt;15&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;-35&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="r data"&gt;11&lt;/TD&gt;
&lt;TD class="r data"&gt;40&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="r data"&gt;12&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="r data"&gt;13&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-left"&gt;See also&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Net-Groups-of-Lines-in-a-Table-to-0-00/m-p/469510" target="_blank"&gt;Solved: Net Groups of Lines in a Table to $0.00 - SAS Support Communities&lt;/A&gt;&amp;nbsp;for an alternative greedy approach.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jan 2022 15:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/792981#M254101</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-28T15:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/793075#M254136</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;,&amp;nbsp;if I could push the 'like' button more than once, I would.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 07:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/793075#M254136</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-01-28T07:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find sum of multiple positive and negative values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/794179#M254625</link>
      <description>Thanks a lot for your speedy response and help</description>
      <pubDate>Thu, 03 Feb 2022 10:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-sum-of-multiple-positive-and-negative-values/m-p/794179#M254625</guid>
      <dc:creator>JoshuaHarris</dc:creator>
      <dc:date>2022-02-03T10:33:36Z</dc:date>
    </item>
  </channel>
</rss>

