<?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: proc optmodel - if then scenario in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296158#M1458</link>
    <description>&lt;P&gt;Thank you for the quick response...It works perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do something similar to fix a particular ID but it didn't work and i'm not sure why. Sorry I am very new to optmodel and still learning some of the basics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; for {j in VARS} do;&lt;BR /&gt;if id[j] = 'd' then fix Assign[i,2] = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are the errors I get:&lt;/P&gt;
&lt;P&gt;ERROR 537-782: The symbol 'id' is unknown.&lt;BR /&gt;ERROR 631-782: The operand types for '=' are mismatched, found a number and a string.&lt;BR /&gt;ERROR 653-782: Subscript 1 must be a string, found a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2016 17:01:34 GMT</pubDate>
    <dc:creator>triley</dc:creator>
    <dc:date>2016-09-02T17:01:34Z</dc:date>
    <item>
      <title>proc optmodel - if then scenario</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296139#M1456</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a problem that Rob Pratt helped me with a little while ago and I was trying to modify the problem slightly and haven't been able to figure out how...What I am trying to do is create 2 groups (ID) with equal amounts of volume (x1-x3) where you can think of x1-x3 as month1, month2, and month3 and the monthly sales volume within each variable. The 2 groups need to have close to the same volume for each month. This is the part that I have done already...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the part i'm stuck on...The ID's currently are part of 4 groups that i want to combine into 2. What I am trying to figure out how to do, is only change the group if it is in ID "1" or "3". The tricky part (at least what I believe is the tricky part) is I don't want to change the group if the ID is in "2" or "4", but I do want to use those ID's volume into the total for the new group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in the end there should be 2 groupID's (1 and 2) and groupID 1 should consist of all of the original ID 2's volume, plus the new volume that comes from ID's 1 and 3. GroupID 2 should consist of all original ID 4's volume, plus the new volume thta comes from ID's 1 and 3.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here was the original set-up:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input id $ curr_grp x1-x3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;a 1 10 15 8&lt;BR /&gt;b 1 11 14 9&lt;BR /&gt;c 1 12 16 10&lt;BR /&gt;d 1 9 16 8&lt;BR /&gt;e 2 8 12 10&lt;BR /&gt;f 2 8 10 11&lt;BR /&gt;g 2 11 14 12&lt;BR /&gt;h 2 13 10 9&lt;BR /&gt;i 3 8 16 15&lt;BR /&gt;j 3 10 11 8&lt;BR /&gt;k 3 11 15 14&lt;BR /&gt;l 3 16 13 10&lt;BR /&gt;m 4 10 15 14&lt;BR /&gt;n 4 12 8 14&lt;BR /&gt;o 4 7 12 13&lt;BR /&gt;p 4 9 14 10&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%let num_vars&amp;nbsp;&amp;nbsp; = 3;&lt;BR /&gt;%let num_groups = 2;&lt;BR /&gt;&lt;BR /&gt;proc optmodel;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set VARS&amp;nbsp;&amp;nbsp; = 1..&amp;amp;num_vars;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set GROUPS = 1..&amp;amp;num_groups;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set&amp;nbsp; &amp;lt;STR&amp;gt; OBS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; num a {OBS, VARS};&lt;BR /&gt;/*&amp;nbsp;&amp;nbsp; num weight {j in VARS} = 1 / max {i in OBS} a[i,j];*/&lt;BR /&gt;read data have&amp;nbsp; into OBS=[id] {j in VARS} &amp;lt;a[id,j]=col('x'||j)&amp;gt; ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; /* Assign[i,g] = 1 if observation i assigned to group g, 0 otherwise */&lt;BR /&gt;&amp;nbsp;&amp;nbsp; var Assign {OBS, GROUPS} binary;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; con AssignOnce {i in OBS}:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum {g in GROUPS} Assign[i,g] = 1;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; con NearlyEqual {g in GROUPS}:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; floor(card(OBS)/&amp;amp;num_groups) &amp;lt;= sum {i in OBS} Assign[i,g] &amp;lt;= ceil(card(OBS)/&amp;amp;num_groups);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; impvar GroupSum {g in GROUPS, j in VARS} = sum {i in OBS} a[i,j] * Assign[i,g];&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; var MinSum {VARS}, MaxSum {VARS};&lt;BR /&gt;&amp;nbsp;&amp;nbsp; con MinSumCon {g in GROUPS, j in VARS}:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MinSum[j] &amp;lt;= GroupSum[g,j];&lt;BR /&gt;&amp;nbsp;&amp;nbsp; con MaxSumCon {g in GROUPS, j in VARS}:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaxSum[j] &amp;gt;= GroupSum[g,j];&lt;BR /&gt;&amp;nbsp;&amp;nbsp; impvar Range {j in VARS} = MaxSum[j] - MinSum[j];&lt;BR /&gt;&amp;nbsp;&amp;nbsp; min Objective = sum {j in VARS} Range[j];&lt;BR /&gt;/*&amp;nbsp;&amp;nbsp; &amp;nbsp;min Objective = sum {j in VARS} weight[j] * Range[j];*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp; solve;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; print Assign;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; print GroupSum;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; num groupID {OBS};&lt;BR /&gt;&amp;nbsp;&amp;nbsp; for {i in OBS} do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for {g in GROUPS: Assign[i,g].sol &amp;gt; 0.5} do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; groupID[i] = g;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; create data want/*(drop=i)*/ from [i] {j in VARS} &amp;lt;col('x'||j)=a[i,j]&amp;gt; groupID;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for the help!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 15:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296139#M1456</guid>
      <dc:creator>triley</dc:creator>
      <dc:date>2016-09-02T15:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel - if then scenario</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296151#M1457</link>
      <description>&lt;P&gt;Your new constraint can be captured by fixing some Assign variables to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you need to declare and read the new curr_grp parameter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   num curr_grp {OBS};
   read data have into OBS=[id] {j in VARS} &amp;lt;a[id,j]=col('x'||j)&amp;gt; curr_grp;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, before the SOLVE statement, you can fix the Assign variables as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   for {i in OBS} do;
      if      curr_grp[i] = 2 then fix Assign[i,1] = 1;
      else if curr_grp[i] = 4 then fix Assign[i,2] = 1;
   end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting optimal solution does respect the fixings:&lt;/P&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: PrintTable" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;[1]&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;curr_grp&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;groupID&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;a&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;b&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;c&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;d&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;e&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;f&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;g&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;h&lt;/TH&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;i&lt;/TH&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="l rowheader" scope="row"&gt;j&lt;/TH&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;k&lt;/TH&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="l rowheader" scope="row"&gt;l&lt;/TH&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;m&lt;/TH&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;n&lt;/TH&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;o&lt;/TH&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;p&lt;/TH&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 02 Sep 2016 16:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296151#M1457</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2016-09-02T16:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel - if then scenario</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296158#M1458</link>
      <description>&lt;P&gt;Thank you for the quick response...It works perfectly!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to do something similar to fix a particular ID but it didn't work and i'm not sure why. Sorry I am very new to optmodel and still learning some of the basics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; for {j in VARS} do;&lt;BR /&gt;if id[j] = 'd' then fix Assign[i,2] = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are the errors I get:&lt;/P&gt;
&lt;P&gt;ERROR 537-782: The symbol 'id' is unknown.&lt;BR /&gt;ERROR 631-782: The operand types for '=' are mismatched, found a number and a string.&lt;BR /&gt;ERROR 653-782: Subscript 1 must be a string, found a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 17:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296158#M1458</guid>
      <dc:creator>triley</dc:creator>
      <dc:date>2016-09-02T17:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel - if then scenario</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296175#M1459</link>
      <description>&lt;P&gt;Glad to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to force every observation with id&amp;nbsp;= 'd' to be assigned to group 2, you can use&amp;nbsp;any one of the following equivalent loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   for {i in OBS} do;
      if i = 'd' then fix Assign[i,2] = 1;
   end;
   for {i in OBS: i = 'd'} do;
      fix Assign[i,2] = 1;
   end;
   for {i in OBS inter {'d'}} do;
      fix Assign[i,2] = 1;
   end;
   for {i in OBS inter {'d'}}
      fix Assign[i,2] = 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know that there is exactly one such observation, you can avoid&amp;nbsp;the FOR loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   fix Assign['d',2] = 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A good way to learn PROC OPTMODEL is to study this book of 29 examples:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/ormpex/68157/HTML/default/viewer.htm#titlepage.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/ormpex/68157/HTML/default/viewer.htm#titlepage.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 18:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296175#M1459</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2016-09-02T18:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel - if then scenario</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296181#M1460</link>
      <description>&lt;P&gt;Great, thank you very much. I will definitely give the book a good read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 18:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/proc-optmodel-if-then-scenario/m-p/296181#M1460</guid>
      <dc:creator>triley</dc:creator>
      <dc:date>2016-09-02T18:06:31Z</dc:date>
    </item>
  </channel>
</rss>

