<?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 Saving output of OPTMODEL in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545064#M2616</link>
    <description>&lt;P&gt;I'm trying to optimize a football team in PROC OPTMODEL. I've successfully created the code which produces the report, but I want to save my decision variables outcome into a dataset. I read the following SAS documentation which suggests to use 'create data' statement, but I'm very new to PROC OPTMODEL and I'm not able to get the expected output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;

set &amp;lt;string&amp;gt; PLAYERS;
set &amp;lt;string&amp;gt; DEF = {"Alonso",	"Azpilicueta",	"Cahill",	"Christensen",	"David Luiz",	"Emerson",	"Moses",	"Rudiger",	"Zappacosta"};
set &amp;lt;string&amp;gt; FWD = {"Abraham","Giroud","Morata"};
set &amp;lt;string&amp;gt; GKP = {"Caballero","Courtois","Kepa"};
set &amp;lt;string&amp;gt; MID = {"Ampadu",	"Bakayoko",	"Barkley",	"Drinkwater",	"Fabregas",	"Hazard",	"Hudson-Odoi",	"Jorginho",	"Kante",	"Kovacic",	"Loftus-Cheek",	"Pedro",	"Willian"};
set &amp;lt;string&amp;gt; WeekMatch;

 
number NewPoints{PLAYERS};
number threshold{WeekMatch};

read data WORK.PLAYERS into PLAYERS = [Name] NewPoints;
read data WORK.THRESH into WeekMatch = [week] threshold;


var x{PLAYERS, WeekMatch} binary;
var win{WeekMatch} binary;


Maximize numberofwin = sum {i in WeekMatch} win[i];

/*constraint on maximum number of times a player can play*/
con ConsecutivePlay {i in PLAYERS}: sum {j in WeekMatch} x[i,j] &amp;lt;= 25; 

/*opponent threshold constraint*/
con WinTotal {j in WeekMatch} : sum {i in PLAYERS} x[i,j] * NewPoints[i] &amp;gt;= threshold[j] * win[j];

/*position constraints*/
con weekDEF {j in WeekMatch} : sum {i in DEF} x[i,j] = 4;

con weekFWD {j in WeekMatch} : sum {i in FWD} x[i,j] = 1;

con weekGKP {j in WeekMatch} : sum {i in GKP} x[i,j] = 1;

con weekMID {j in WeekMatch} : sum {i in MID} x[i,j] = 5;

solve with milp;

print numberofwin x win;
create data numberofwin from count=numberofwin;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The supporting data is attached.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 21:31:19 GMT</pubDate>
    <dc:creator>lawilap</dc:creator>
    <dc:date>2019-03-21T21:31:19Z</dc:date>
    <item>
      <title>Saving output of OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545064#M2616</link>
      <description>&lt;P&gt;I'm trying to optimize a football team in PROC OPTMODEL. I've successfully created the code which produces the report, but I want to save my decision variables outcome into a dataset. I read the following SAS documentation which suggests to use 'create data' statement, but I'm very new to PROC OPTMODEL and I'm not able to get the expected output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;

set &amp;lt;string&amp;gt; PLAYERS;
set &amp;lt;string&amp;gt; DEF = {"Alonso",	"Azpilicueta",	"Cahill",	"Christensen",	"David Luiz",	"Emerson",	"Moses",	"Rudiger",	"Zappacosta"};
set &amp;lt;string&amp;gt; FWD = {"Abraham","Giroud","Morata"};
set &amp;lt;string&amp;gt; GKP = {"Caballero","Courtois","Kepa"};
set &amp;lt;string&amp;gt; MID = {"Ampadu",	"Bakayoko",	"Barkley",	"Drinkwater",	"Fabregas",	"Hazard",	"Hudson-Odoi",	"Jorginho",	"Kante",	"Kovacic",	"Loftus-Cheek",	"Pedro",	"Willian"};
set &amp;lt;string&amp;gt; WeekMatch;

 
number NewPoints{PLAYERS};
number threshold{WeekMatch};

read data WORK.PLAYERS into PLAYERS = [Name] NewPoints;
read data WORK.THRESH into WeekMatch = [week] threshold;


var x{PLAYERS, WeekMatch} binary;
var win{WeekMatch} binary;


Maximize numberofwin = sum {i in WeekMatch} win[i];

/*constraint on maximum number of times a player can play*/
con ConsecutivePlay {i in PLAYERS}: sum {j in WeekMatch} x[i,j] &amp;lt;= 25; 

/*opponent threshold constraint*/
con WinTotal {j in WeekMatch} : sum {i in PLAYERS} x[i,j] * NewPoints[i] &amp;gt;= threshold[j] * win[j];

/*position constraints*/
con weekDEF {j in WeekMatch} : sum {i in DEF} x[i,j] = 4;

con weekFWD {j in WeekMatch} : sum {i in FWD} x[i,j] = 1;

con weekGKP {j in WeekMatch} : sum {i in GKP} x[i,j] = 1;

con weekMID {j in WeekMatch} : sum {i in MID} x[i,j] = 5;

solve with milp;

print numberofwin x win;
create data numberofwin from count=numberofwin;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The supporting data is attached.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545064#M2616</guid>
      <dc:creator>lawilap</dc:creator>
      <dc:date>2019-03-21T21:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Saving output of OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545076#M2617</link>
      <description>&lt;P&gt;The following statement will create a data set with one observation for each assignment that appears in the solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data solution from [i j]={i in PLAYERS, j in WeekMatch: x[i,j].sol &amp;gt; 0.5};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you prefer the column names to be player and week, you can do this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data solution from [player=i week=j]={i in PLAYERS, j in WeekMatch: x[i,j].sol &amp;gt; 0.5};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you prefer week to appear as the first column, you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data solution from [week=j player=i]={j in WeekMatch, i in PLAYERS: x[i,j].sol &amp;gt; 0.5};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a two-dimensional table of 0 and 1, you can do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data solution from [player=i]=PLAYERS {j in WeekMatch} &amp;lt;col(j)=x[i,j].sol&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 00:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545076#M2617</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-03-22T00:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Saving output of OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545085#M2618</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;Thank you so much, this works very well. I was particularly interested in the last solution you mentioned.&lt;/P&gt;&lt;P&gt;But, this only give me the dataset for x, can you please suggest how to store 'win'.&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 22:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545085#M2618</guid>
      <dc:creator>lawilap</dc:creator>
      <dc:date>2019-03-21T22:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Saving output of OPTMODEL</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545110#M2619</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create data windata from [week] win;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 01:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Saving-output-of-OPTMODEL/m-p/545110#M2619</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-03-22T01:00:21Z</dc:date>
    </item>
  </channel>
</rss>

