<?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 access a value of local variable and assign it to global variable inside proc optmodel? in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557346#M2740</link>
    <description>&lt;P&gt;Look into the _OROPTMODEL_ macro variable for the substring OBJECTIVE=value. To quote the documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;The OPTMODEL procedure creates a macro variable named _OROPTMODEL_. 
You can inspect the execution of the most recently invoked solver from the value of the 
macro variable. The macro variable is defined at the start of the procedure and updated 
after each SOLVE statement is executed. The OPTMODEL procedure also updates the 
macro variable when an error is detected. 

The _OROPTMODEL_ value is a string that consists of several "KEYWORD=value" items in 
sequence, separated by blanks; for example: 

STATUS=OK ALGORITHM=DS SOLUTION_STATUS=OPTIMAL 
OBJECTIVE=119302.04331 PRIMAL_INFEASIBILITY=3.552714E-13 
DUAL_INFEASIBILITY=2.273737E-13 BOUND_INFEASIBILITY=0 
ITERATIONS=82 PRESOLVE_TIME=0.02 SOLUTION_TIME=0.05


The information contained in _OROPTMODEL_ varies according 
to which solver was last called. For lists of keywords and possible 
values, see the individual solver chapters. 
&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 May 2019 02:41:10 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-05-09T02:41:10Z</dc:date>
    <item>
      <title>How to access a value of local variable and assign it to global variable inside proc optmodel?</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557300#M2739</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My problem is how to save optimal value of the objective function from one optmodel procedure into the global variable. I need this in order to use it in the second optmodel procedure. I've prepared a simple (dummy) example code which illustrates my problem.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET OptimalValue=0;&lt;BR /&gt;
%macro outer;
  %firstmodel(5);
  *other code;
  %put "opt in outer =" &amp;amp;OptimalValue;
%mend outer;&lt;BR /&gt;
%macro firstmodel(i);
  proc optmodel;
    num y;
    var x;
    max f=x;
    con c1: x&amp;lt;=&amp;amp;i;
    solve;
    y=f;
    put y;
    %let OptimalValue = y; *here string "y" is assigned to OptimalValue, not the value of y;
    %put "opt in first model=" &amp;amp;OptimalValue;
  quit;
%mend firstmodel;
%outer;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How to access a value of local variable and assign it to global variable inside proc optmodel?&lt;/P&gt;&lt;P&gt;In fifth line from the bottom of code SAS understands y as string and not as a variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any help. Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 21:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557300#M2739</guid>
      <dc:creator>renaba</dc:creator>
      <dc:date>2019-05-08T21:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to access a value of local variable and assign it to global variable inside proc optmodel?</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557346#M2740</link>
      <description>&lt;P&gt;Look into the _OROPTMODEL_ macro variable for the substring OBJECTIVE=value. To quote the documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;The OPTMODEL procedure creates a macro variable named _OROPTMODEL_. 
You can inspect the execution of the most recently invoked solver from the value of the 
macro variable. The macro variable is defined at the start of the procedure and updated 
after each SOLVE statement is executed. The OPTMODEL procedure also updates the 
macro variable when an error is detected. 

The _OROPTMODEL_ value is a string that consists of several "KEYWORD=value" items in 
sequence, separated by blanks; for example: 

STATUS=OK ALGORITHM=DS SOLUTION_STATUS=OPTIMAL 
OBJECTIVE=119302.04331 PRIMAL_INFEASIBILITY=3.552714E-13 
DUAL_INFEASIBILITY=2.273737E-13 BOUND_INFEASIBILITY=0 
ITERATIONS=82 PRESOLVE_TIME=0.02 SOLUTION_TIME=0.05


The information contained in _OROPTMODEL_ varies according 
to which solver was last called. For lists of keywords and possible 
values, see the individual solver chapters. 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 02:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557346#M2740</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-05-09T02:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to access a value of local variable and assign it to global variable inside proc optmodel?</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557388#M2741</link>
      <description>&lt;P&gt;Thanks PGStats for your answer,&lt;/P&gt;&lt;P&gt;In _OROPTMODEL_ variable there is also optimal value (among other), but I have an optimal value also in my local variable y.&lt;/P&gt;&lt;P&gt;Your hint about looking at _OROPTMODEL_ documentation lead me to "SYMGET" and "CALL SYMPUT". The last one turned out to be a needed element.&lt;/P&gt;&lt;P&gt;Below, is a corrected version of my code - just for someone who would have similar problem with assignment of local variable to global variable.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET OptimalValue=0;
%macro outer;
  %firstmodel(8);
  *other code;
  %put "opt in outer =" &amp;amp;OptimalValue;
%mend outer;
%macro firstmodel(i);
  proc optmodel;
    num y;
	var x;
	max f=x;
	con c1: x&amp;lt;=&amp;amp;i;
	solve;
	y=f;
	put y;
	call symput('OptimalValue',trim(left(put(y,8.))));
	%put "opt in first model=" &amp;amp;OptimalValue;
  quit;
%mend firstmodel;
%outer;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 09:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/How-to-access-a-value-of-local-variable-and-assign-it-to-global/m-p/557388#M2741</guid>
      <dc:creator>renaba</dc:creator>
      <dc:date>2019-05-09T09:24:32Z</dc:date>
    </item>
  </channel>
</rss>

