<?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: Solver in SAS - select rows that sum to a given value (with more than one constraint) in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544128#M2605</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267007"&gt;@sanjanko&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;You can try the following using the if-then-else construct. Similar to excel, here this will create a new data set which is an exact copy of what you have and add a new column with the logical condition. I am not sure if SAS would be ok with the period in your column name, If possible, I would rename that column in your source.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want; 
    Set Have; 
    If Volume = 700 and Tot. cost = 5700 Then MyFlag = 1;
    Else MyFlag = 0 ;
Run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Mar 2019 00:37:34 GMT</pubDate>
    <dc:creator>UdayGuntupalli</dc:creator>
    <dc:date>2019-03-19T00:37:34Z</dc:date>
    <item>
      <title>Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544127#M2604</link>
      <description>&lt;P&gt;Small sample of data I have - for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Volume&amp;nbsp; Price&amp;nbsp;&amp;nbsp; Tot. cost(vol*price)&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 500&lt;/P&gt;&lt;P&gt;200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1200&lt;/P&gt;&lt;P&gt;300&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2100&lt;/P&gt;&lt;P&gt;400&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3200&lt;/P&gt;&lt;P&gt;500&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4500&lt;/P&gt;&lt;P&gt;1000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to select the rows where: 1) Tot volume= 700 and 2) Tot. cost=5700.&lt;/P&gt;&lt;P&gt;In excel I use a binary variable that I multiply with Volume and Tot. cost and, after solving, it becomes 1 if the rows is selected and 0 otherwise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not able to replicate this kind of solver in SAS. Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 23:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544127#M2604</guid>
      <dc:creator>sanjanko</dc:creator>
      <dc:date>2019-03-18T23:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544128#M2605</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267007"&gt;@sanjanko&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;You can try the following using the if-then-else construct. Similar to excel, here this will create a new data set which is an exact copy of what you have and add a new column with the logical condition. I am not sure if SAS would be ok with the period in your column name, If possible, I would rename that column in your source.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want; 
    Set Have; 
    If Volume = 700 and Tot. cost = 5700 Then MyFlag = 1;
    Else MyFlag = 0 ;
Run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 00:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544128#M2605</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2019-03-19T00:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544129#M2606</link>
      <description>&lt;P&gt;I need to select the rows that sum up to Tot. Volume = 700. In this example, in order to obtain that Volume I need to select row 2 and row 5. All the others should not be selected. I am not able to do this selection of rows. In Solver Excel works, but I don't know how to reproduce it in SAS. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 00:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544129#M2606</guid>
      <dc:creator>sanjanko</dc:creator>
      <dc:date>2019-03-19T00:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544130#M2607</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267007"&gt;@sanjanko&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; When you say select the rows, the equivalent in SAS that I am aware of is to create a subset of the original dataset which meets your conditions, you can do that using the if-then-else construct or where construct like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
   set have; *where have is the name of the dataset that you have;
   Where Tot. Volume = 700;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Mar 2019 00:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544130#M2607</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2019-03-19T00:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544132#M2608</link>
      <description>&lt;P&gt;I start from this data:&lt;/P&gt;&lt;P&gt;Volume Price Tot. cost(vol*price)&lt;/P&gt;&lt;P&gt;100 5 500&lt;/P&gt;&lt;P&gt;200 6 1200&lt;/P&gt;&lt;P&gt;300 7 2100&lt;/P&gt;&lt;P&gt;400 8 3200&lt;/P&gt;&lt;P&gt;500 9 4500&lt;/P&gt;&lt;P&gt;1000 5 5000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to obtain only that:&lt;/P&gt;&lt;P&gt;Volume Price Tot. cost(vol*price)&lt;/P&gt;&lt;P&gt;200 6 1200&lt;/P&gt;&lt;P&gt;500 9 4500&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only want to select these rows. The problem is that the sum of 200 and 500 gives me 700. It's not one unique row with 700,&amp;nbsp; but the sum. I need to tell SAS that it has to select rows that sum up to a certain value. This should be done with: PROC OPTMODEL; just my code does't work. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 00:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544132#M2608</guid>
      <dc:creator>sanjanko</dc:creator>
      <dc:date>2019-03-19T00:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544145#M2609</link>
      <description>What code? You haven't shown any code? &lt;BR /&gt;You're expecting exactly the values 700 and 5700?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Mar 2019 02:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544145#M2609</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-19T02:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544148#M2610</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267007"&gt;@sanjanko&lt;/a&gt;&amp;nbsp; &amp;nbsp;See if this works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Volume  Price   Tot  ;
cards;
100          5            500
200          6            1200
300          7             2100
400          8            3200
500          9            4500
1000        5             5000
;

proc sql;
create table want(drop=s v) as
select a.* ,b.volume as v,sum(a.volume,b.volume)=700 as s
from have a, have(keep=volume) b 
group by s
having (min(a.volume)=a.volume and s) or (min(b.volume)=b.volume and s );
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Mar 2019 02:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544148#M2610</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-19T02:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544153#M2611</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set OBS;
   num volume {OBS};
   num price {OBS};
   num cost {i in OBS} = volume[i] * price[i];
   read data have into OBS=[_N_] volume price;

   var X {OBS} binary;
   con TotalVolume:
      sum {i in OBS} volume[i] * X[i] = 700;
   con TotalCost:
      sum {i in OBS} cost[i] * X[i] = 5700;

   solve noobj;
   create data want from [i]={i in OBS: X[i].sol &amp;gt; 0.5} volume price cost;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Mar 2019 04:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544153#M2611</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-03-19T04:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Solver in SAS - select rows that sum to a given value (with more than one constraint)</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544154#M2612</link>
      <description>&lt;P&gt;Thanks a lot! That's exactly what I need!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 04:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Solver-in-SAS-select-rows-that-sum-to-a-given-value-with-more/m-p/544154#M2612</guid>
      <dc:creator>sanjanko</dc:creator>
      <dc:date>2019-03-19T04:34:07Z</dc:date>
    </item>
  </channel>
</rss>

