<?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: Optimizing a macro output in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105216#M644</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Regarding linear interpolation, PROC OPTMODEL does not have anything built in.&amp;nbsp; But you can try some of the ideas suggested in this blog posting:&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2012/03/16/linear-interpolation-in-sas/"&gt;http://blogs.sas.com/content/iml/2012/03/16/linear-interpolation-in-sas/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and this Usage Note:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/560.html"&gt;http://support.sas.com/kb/24/560.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do the interpolation outside of OPTMODEL and then read the results into an OPTMODEL array.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 May 2012 19:04:20 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2012-05-09T19:04:20Z</dc:date>
    <item>
      <title>Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105202#M630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have both SAS/OR and SAS/IML and would like to perform nonlinear optimization on the values returned by a macro. This macro takes A and B as input and returns a result specific for the A and B values. There are also lower and upper bounds on both A and B, I have given a pseudo code that explains this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MACRO returnResult(A, B)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...................................&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...................................&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...................................&lt;/P&gt;&lt;P&gt;&amp;nbsp; result = function (A, B)&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The objective function to minimized is the "result" returned by the macro with upper and lower bounds on A and B. Can some please help how we can set it up as a nonlinear optimization problem using SAS/OR or SAS/IML?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 May 2012 23:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105202#M630</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-04T23:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105203#M631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Specifically, if I have a macro that contains the following data steps that calculates the objective function, is it possible to use them with in either PROC IML or OPTMODEL (I am new to both). Any help would be appreciated. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*create some test data*/&lt;/P&gt;&lt;P&gt;DATA test (drop=i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; input X Y Z;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 2000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 10 0&lt;/P&gt;&lt;P&gt;2 20 0&lt;/P&gt;&lt;P&gt;3 30 0&lt;/P&gt;&lt;P&gt;4 40 0&lt;/P&gt;&lt;P&gt;5 50 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if 0 then set test nobs=nobs;&lt;/P&gt;&lt;P&gt;CALL SYMPUT('NUMREC',nobs);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*** put # of records into NUMREC macro var ***/&lt;/P&gt;&lt;P&gt;stop;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*** stop, got number of records ***/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* now read values of x and y into arrays, and then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; reread test and do calculations*/&lt;/P&gt;&lt;P&gt;data want (drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array _xval(&amp;amp;numrec); /* create two arrays with same number of&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elements as there are records in test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array _yval(&amp;amp;numrec);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until (eof1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* load the array with x and y values */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test end=eof1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _xval(i)=x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _yval(i)=y;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rec=-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do until (eof2);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* read in each record separately */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test end=eof2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _rec+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _i=1 to _rec;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; z+_xval(_i)*_yval(&amp;amp;numrec-_rec+_i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 May 2012 19:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105203#M631</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-06T19:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105204#M632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do something like the following in OPTMODEL:&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set OBS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num x {OBS};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num y {OBS};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num n = card(OBS);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read data test into OBS=[_N_] x y;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num z {j in OBS} = sum {i in 1..j-1} x&lt;I&gt; * y[n-j+i];&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create data want(drop=i) from &lt;I&gt; x y z;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But that just calculates z from the given values of x and y.&amp;nbsp; Are x and y intended to be the decision variables in your optimization problem?&amp;nbsp; Do you have any constraints on x and y?&amp;nbsp; And do you want to minimize or maximize z?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2012 21:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105204#M632</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-07T21:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105205#M633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to do optimization of a two variable (x and y) macro function. The macro takes as input x and y and returns the corresponding sum of squared errors which needs to be minimized. There are upper and lower bounds to both x and y. The macro is a fairly complex one with several data steps (I can include the entire macro within in optimization procedure as I have done below). i would like to use a quasi newton approach to determine the optimal values of x and y that minimizes the objective function. I have both SAS/OR and SAS/IML but have difficulty finding out the right approach for solving this problem. I tried using SAS/IML as follows using a dummy objective function calculation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;iml&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;start&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; F_ROSEN(x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: red; font-size: 10pt;"&gt;submit&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.9&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;PROC&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;SQL&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;NOPRINT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; SUM(x) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; :SUMM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;QUIT&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: red; font-size: 10pt;"&gt;endsubmit&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;newSum = &amp;amp;SUMM;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y1 = &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;10&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; * (x[&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;] - x[&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;] * x[&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y2 =&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; - x[&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f&amp;nbsp; = &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;0.5&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; * (y1 * y1 + y2 * y2)+newSum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(f);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: red; font-size: 10pt;"&gt;finish&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; F_ROSEN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; x = {-&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1.2&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;1 1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; optn = {&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;0&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;2&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;.&lt;/STRONG&gt; &lt;STRONG style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: red; font-size: 10pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; nlpqn(rc,xr,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; font-size: 10pt;"&gt;"F_ROSEN"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;,x,optn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;However, the problem with this approach is that, I believe, the function f needs to be defined in terms of the decision variables (x and y). However, in my case it is just the sum of squared errors corresponding to a particular value of x and y .i.e. &lt;SPAN style="font-family: 'Courier New';"&gt;f&amp;nbsp; = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&amp;amp;SUMM;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;Please let me know if this can be handled in SAS.&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;Thank you.&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; text-align: -webkit-auto; background-color: rgba(255, 255, 255, 0.917969);"&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2012 21:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105205#M633</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-07T21:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105206#M634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, your objective function should be expressed in terms of your decision variables, as in this "Getting Started" example:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/ormpug/63975/HTML/default/viewer.htm#ormpug_optmodel_sect003.htm"&gt;http://support.sas.com/documentation/cdl/en/ormpug/63975/HTML/default/viewer.htm#ormpug_optmodel_sect003.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it is still not clear to me whether your x and y are decision variables or input data.&amp;nbsp; Maybe it would help to describe your optimization problem mathematically, without code.&amp;nbsp; What is your input, and what is your desired output?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2012 22:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105206#M634</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-07T22:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105207#M635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have given a simple example of what I am trying to do. In the following macro, x1 and x2 are the decision variables and SSE is the objective function that is to be minimized. (The one I have given is fairly simple and the actual code has far more calculations to arrive at SSE). SSE = f(x1, x2) is the objective function but it is not possible to write out the calculation since calculations are not straight forward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; test; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; hours actualRisk;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.2 0.05&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.3 0.008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp; 0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7 0.09&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.9 0.15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3 0.1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7.5 0.25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 0.20&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.5 0.1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.7 0.15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; generateSSE(x1, x2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; DATA test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; SET test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; calculatedRisk = CDF(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 10pt;"&gt;'WEIBULL'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;,hours,&amp;amp;x1,&amp;amp;x2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; data test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; squaredErrors = (actualRisk - calculatedRisk)*(actualRisk - calculatedRisk);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; PROC SQL NOPRINT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; SELECT SUM(squaredErrors) into :SSE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; FROM test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;%PUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &amp;amp;SSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;%MEND&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; generateSSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;generateSSE&lt;/EM&gt;&lt;/STRONG&gt;(&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Could you please let me know how to pass generateSSE to an optimizer to find the values of x1 and x2 that minimizes SSE?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;I have implemented the same using the optim function in R and have given the code below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;hours &amp;lt;- c(1.2, 0.3, 10, 7, 2.9, 3, 7.5, 8, 3.5, 1.7)&lt;BR /&gt;actualRisk &amp;lt;- c(0.05, 0.008, 0.5, 0.09, 0.15, 0.1, 0.25, 0.20, 0.1, 0.15)&lt;/P&gt;&lt;P&gt;test &amp;lt;- data.frame(hours = hours, actualRisk = actualRisk)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;generateSSE &amp;lt;- function(x)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; test$calculatedRisk &amp;lt;- dweibull(test$hours, shape = x[1], scale = x[2])&lt;BR /&gt;&amp;nbsp; test$squaredErrors &amp;lt;- (test$actualRisk - test$calculatedRisk)^2&lt;BR /&gt;&amp;nbsp; return(sum(test$squaredErrors))&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;optout=optim(c(1,2), generateSSE, NULL, method = "L-BFGS-B",&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lower=rep(0.4,0.05), upper=rep(8, 1000),control=list(reltol=0.01))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;I would like to implement a similar solution in SAS.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Ravi&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 07:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105207#M635</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-08T07:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105208#M636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the clarification.&amp;nbsp; If I understand your example correctly, the following code solves the problem in one PROC OPTMODEL call, without using any macros.&amp;nbsp; Maybe your more complicated objective can be handled similarly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data bounds;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input lower upper;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;BR /&gt;0.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;BR /&gt;0.05 1000&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set OBS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num hours {OBS};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; num actualRisk {OBS};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read data test into OBS=[_N_] hours actualRisk;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set VARS;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var x {VARS};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; read data bounds into VARS=[_N_] x.lb=lower x.ub=upper;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; impvar calculatedRisk {i in OBS} = CDF('WEIBULL',hours&lt;I&gt;,x[1],x[2]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; min SSE = sum {i in OBS} (actualRisk&lt;I&gt; - calculatedRisk&lt;I&gt;)^2;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; solve;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print x;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print actualRisk calculatedRisk;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create data x_sol from [var] x;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 13:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105208#M636</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-08T13:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105209#M637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot Rob for your solution. I will take a look at it and see whether we could rewrite the entire objective function the same way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A quick question: Is it possible to use call PROC IML within PROC OPTMODEL since objective function calculation involves matrix multiplications???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105209#M637</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-08T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105210#M638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot currently call PROC IML from within PROC OPTMODEL.&amp;nbsp; In release 12.1 due out later this year, you can use a SUBMIT block to call generic SAS code from within PROC OPTMODEL.&amp;nbsp; But even that functionality will not enable you to implement a black-box objective function.&amp;nbsp; Instead, you can indicate matrix multiplication by using the SUM operator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c[i,j] = sum {k in 1..n} a[i,k] * b[k,j]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 15:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105210#M638</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-08T15:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105211#M639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Rob for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 18:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105211#M639</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-08T18:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105212#M640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to program the whole objective function and need help in the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. How do I create the reverse of "impvar calculatedRisk {i in OBS} = CDF('WEIBULL',hours&lt;I&gt;,x[1],x[2])" ?? I want this variable or array the same elements as calculatedRisk but in a reverse order???&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Can I create another variable newRisk such that newRisk[1] = calculatedRisk[1] and all the other values of newRisk[] are zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Can I multiply the individual elements of calculatedRisk and newRisk??? First element of one with the last element of the other and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if these are possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 20:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105212#M640</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-08T20:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105213#M641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can do all of these things, but it will likely be inefficient to introduce new variables whose values are equal to existing variables.&amp;nbsp; Instead, you can express everything in terms of calculatedRisk&lt;I&gt; for different values of i.&amp;nbsp; For example, to achieve #1, you can do the following:&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;num n = card(OBS);&lt;/P&gt;&lt;P&gt;impvar calculatedRiskReverse {i in OBS} = calculatedRisk[n-i+1];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But you can avoid introducing a new variable by just using calculatedRisk[n-i+1] everywhere you need it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for {i in OBS} put calculatedRisk[n-i+1]=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For #2:&lt;/P&gt;&lt;P&gt;impvar newRisk {i in OBS} = (if i = 1 then calculatedRisk[1] else 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For #3:&lt;/P&gt;&lt;P&gt;calculatedRisk&lt;I&gt; * newRisk[n-i+1]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, I think you will be better off not introducing additional variables unless you need to.&amp;nbsp; If you write out the full expression for your objective, I suspect you will find that you can eliminate the additional variables by using logical conditions in the SUM operator.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 22:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105213#M641</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-08T22:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105214#M642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help on those questions. As I am coding up the remaining objective function, I have a couple of more questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I want to implement the following for loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for (i in 2:n))&lt;BR /&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; updatedRisk1&lt;I&gt;=&amp;nbsp; sum(calculatedRisk[1:i-1]*newRisk[(n-i+2):n])&lt;BR /&gt;&amp;nbsp; }&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried using the DO loop as follows.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;impvar&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; updatedRisk {i in OBS} = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;num j&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; j = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; to n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; updatedRisk&lt;J&gt; = sum(calculatedRisk[&lt;/J&gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1:j&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;]*newRisk[(n-j+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;n&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;However, neither the impvar statement nor the do loop is working as expected. Could you please help me with the right approach for this???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;2. I am trying to do interpolation on a variable as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; input;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; var1 value;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;1&amp;nbsp; 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;2 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;3 15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;4 20&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;5 25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Based on the value of var1, I am trying to interpolate for&amp;nbsp; var2 as given below (these are not separate datasets but just the variables created within OPTMODEL. I have variables var1, var2 and value created using IMPVAR and would like to impute "value" for var2.) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; var2 interpolatedValue;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;1.5&amp;nbsp; 7.5&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;2.5 12.5&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;3.5 17.5&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 10pt;"&gt;4.5 22.5&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Even if linear interpolation is not possible, the nearest approximation is sufficient as in the following R code using approx function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;yinterp=approx(var1,value,xout=var2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Please let me know if there is a way to implement this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Thanks again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Ravi&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 18:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105214#M642</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-09T18:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105215#M643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will reply to #1 first and #2 in a separate post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to use IMPVAR, you have to include the formula in the declaration.&amp;nbsp; You cannot update it later.&amp;nbsp; The other problem is that the SUM operator has different syntax than what you tried.&amp;nbsp; Here's what I think you wanted (a dot product of two vectors):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;impvar updatedRisk {i in 2..n} = sum {j in 1..i-1} calculatedRisk&lt;J&gt; * newRisk[n-i+1+j];&lt;/J&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 18:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105215#M643</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-09T18:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105216#M644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Regarding linear interpolation, PROC OPTMODEL does not have anything built in.&amp;nbsp; But you can try some of the ideas suggested in this blog posting:&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2012/03/16/linear-interpolation-in-sas/"&gt;http://blogs.sas.com/content/iml/2012/03/16/linear-interpolation-in-sas/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and this Usage Note:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/560.html"&gt;http://support.sas.com/kb/24/560.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do the interpolation outside of OPTMODEL and then read the results into an OPTMODEL array.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 19:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105216#M644</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-09T19:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105217#M645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply. I have a couple of questions on this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. First, the do loop I have showed contains more statements than that I showed you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, the following one has two statements that needs to be updated simultaneously with each run of the do loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; j = &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; to n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; updatedRisk&lt;J&gt; = sum(calculatedRisk[&lt;/J&gt;&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1:j&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;]*newRisk[(n-j+&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;n&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; actualRisk&lt;J&gt; = calculatedRisk&lt;J&gt; + updatedRisk&lt;J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Is there a way to capture multiple statements as shown inside do loop???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;2. Some of the variables declared using IMPVAR will be updated later in the code as I have shown with actualRisk in the do loop?? How do I accomplish this since you mention that formula has to be included in the declaration itself?? In my case, I will declare using IMPVAR once and again update the same variable later in the code. Is it feasible??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Ravi&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 19:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105217#M645</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-09T19:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105218#M646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure if doing interpolation outside OPTMODEL would work since the calculation of sum of squared errors is done based on the interploated values. So the interpolated values depend on the decision variables x[1] and x[2]. If not interpolation, just the nearest approximation would be sufficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 19:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105218#M646</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-09T19:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105219#M647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Yes, you can have multiple statements within a DO loop.&lt;/P&gt;&lt;P&gt;2. No, you cannot update the formula for an IMPVAR after the declaration.&amp;nbsp; I gave correct syntax for the updatedRisk IMPVAR declaration in the previous reply.&amp;nbsp; I think you just need a second IMPVAR statement for actualRisk.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure, but it looks to me like you might be trying to calculate your objective function by writing a DO loop.&amp;nbsp; In OPTMODEL, objectives are instead declared with a single algebraic expression.&amp;nbsp; In your case, you might need to use the SUM operator with multiple-dimensional indices, something like:&lt;/P&gt;&lt;P&gt;sum {i in 1..n, j in 1..i, k in 1..j} mynum[i,j,k] * myvar[i,j,k].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you write out your objective function on paper as a single algebraic expression, the conversion to the corresponding OPTMODEL code will be immediate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 19:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105219#M647</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-09T19:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105220#M648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The main problem for us stems from the fact that there is no single equation for the objective funtion but a series of calculations that culminates in one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried the DO loop implementation as follows but getting an error that "&lt;STRONG&gt;A variable declaration may not be a nested statement&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; j = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; to n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;impvar&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; updatedRisk{i in &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;j&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;} =&amp;nbsp; sum {i in &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1..j&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;} calculatedRisk&lt;I&gt; * newRisk[n-j+&lt;/I&gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;+i];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;impvar&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt; newRisk2{i in j} = newRisk1{i in j} + actualRisk{i in j};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does it mean that an impvar statement cannot be used within in a DO loop??? Please clarify.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 20:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105220#M648</guid>
      <dc:creator>vioravis</dc:creator>
      <dc:date>2012-05-09T20:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing a macro output</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105221#M649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is correct.&amp;nbsp; Declarations (IMPVAR, VAR, NUM, etc.) cannot be nested in other statements (DO, FOR, etc.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See &lt;A href="http://support.sas.com/documentation/cdl/en/ormpug/63975/HTML/default/viewer.htm#ormpug_optmodel_sect019.htm"&gt;http://support.sas.com/documentation/cdl/en/ormpug/63975/HTML/default/viewer.htm#ormpug_optmodel_sect019.htm&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 21:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Optimizing-a-macro-output/m-p/105221#M649</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2012-05-09T21:10:34Z</dc:date>
    </item>
  </channel>
</rss>

