<?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 how  to use arrays can any one help on this in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-optmodel-how-to-use-arrays-can-any-one-help-on-this/m-p/224424#M267367</link>
    <description>&lt;P&gt;Answered offline via email discussion.&amp;nbsp; The final code, shown below,&amp;nbsp;did not use any macros.&amp;nbsp; Also, questions about PROC OPTMODEL in SAS/OR are better suited for the Mathematical Optimization and Operations Research Community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variables = 12;

data indata;
   input X1-X&amp;amp;variables;
   datalines;
0.1153   0.3095   0.0749   0.1320   0.1043   0.0434   0.0086   0.0225   0.0162   0.0312   0.0159   0.1261
0.1504   0.3091   0.0794   0.1308   0.0471   0.0491   0.0057   0.0199   0.0327   0.0252   0.0160   0.1344
0.2557   0.2531   0.0906   0.0932   0.0386   0.0495   0.0047   0.0180   0.0336   0.0208   0.0113   0.1308
0.2894   0.2535   0.0846   0.0447   0.0530   0.0518   0.0042   0.0177   0.0260   0.0166   0.0134   0.1451
0.2692   0.2765   0.0830   0.0259   0.0598   0.0524   0.0122   0.0184   0.0241   0.0168   0.0131   0.1486
0.3013   0.2538   0.0765   0.0297   0.0435   0.0452   0.0132   0.0186   0.0240   0.0172   0.0130   0.1642
0.3077   0.2485   0.0812   0.0437   0.0418   0.0449   0.0368   0.0201   0.0266   0.0119   0.0125   0.1245
0.2825   0.2347   0.0829   0.0779   0.0421   0.0449   0.0415   0.0253   0.0253   0.0139   0.0184   0.1105
0.2822   0.2237   0.0889   0.0509   0.0550   0.0431   0.0404   0.0246   0.0276   0.0169   0.0128   0.1338
0.3030   0.2273   0.0936   0.0718   0.0543   0.0572   0.0377   0.0302   0.0232   0.0165   0.0113   0.0737
;

proc optmodel;
   set OBS;
   num c {OBS, 1..&amp;amp;variables};
   read data indata into OBS=[_N_] {j in 1..&amp;amp;variables} &amp;lt;c[_N_,j]=col('X'||j)&amp;gt;;

   ************* step 1********************;
   set EQS = (OBS diff {1}) cross 1..&amp;amp;variables;
   var u{EQS}&amp;gt;= 0,v{EQS}&amp;gt;= 0;

   ************* step 2********************;
   var x {1..&amp;amp;variables, 1..&amp;amp;variables} &amp;gt;= 0;

   ************* step 3********************;
   min z = sum{&amp;lt;i,j&amp;gt; in EQS} u[i,j] + sum{&amp;lt;i,j&amp;gt; in eqs} v[i,j];

   ************* step 4********************;
   con Mycon {&amp;lt;i,j&amp;gt; in EQS}:
      sum {k in 1..&amp;amp;variables} c[i-1,k] * x[k,j] + u[i,j] - v[i,j] = c[i,j];

   ************* step 5********************;
   con SumToOne {i in 1..&amp;amp;variables}:
      sum {k in 1..&amp;amp;variables} x[i,k] = 1;

   solve;

   ************* step 6********************;
   print x;
   create data tm_all from [col1=i]=(1..&amp;amp;variables) {k in 1..&amp;amp;variables} &amp;lt;col('x'||k)=x[k,i]&amp;gt;;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 08 Sep 2015 15:41:17 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2015-09-08T15:41:17Z</dc:date>
    <item>
      <title>proc optmodel how  to use arrays can any one help on this</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-optmodel-how-to-use-arrays-can-any-one-help-on-this/m-p/210287#M267366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let x= 3; are may be increas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let eq = 300;&lt;/P&gt;&lt;P&gt;%macro code;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;/P&gt;&lt;P&gt;ods output printtable = TM_ALL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var u{i in 1..&amp;amp;eq}&amp;gt;= 0,v{i in 1..&amp;amp;eq}&amp;gt;= 0,&lt;/P&gt;&lt;P&gt;&amp;nbsp; min z = sum{i in 1..&amp;amp;eq} u&lt;I&gt; + sum{i in 1..&amp;amp;eq} v&lt;I&gt;;con&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;C1: 0.23 * x1[1] + 0.88 * x2[1] + 0.5549 * x3[1] + 0.1342&amp;nbsp;&amp;nbsp; + u[1]-v[1] =0.88,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;like upt0 300 c1 to c300 constraints are there how to use here loops are arrays any suggestion on my code. help on this&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i tried another example i got but i have use calculation like &lt;/P&gt;&lt;P&gt;%do z = 1 %to &amp;amp;variables;&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum {i in 1..&amp;amp;variables} x&amp;amp;z.&lt;I&gt;=1&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %If &amp;amp;z. &amp;lt; &amp;amp;variables %then %let com1 =,;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %let com1 = ; &amp;amp;com1.&lt;/P&gt;&lt;P&gt;%end;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; solve;&lt;/P&gt;&lt;P&gt;print&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do z=1 %to &amp;amp;variables;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x&amp;amp;z %end;;&lt;/P&gt;&lt;P&gt;quit;&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;%mend;&lt;/P&gt;&lt;P&gt;%code;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Aug 2015 19:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-optmodel-how-to-use-arrays-can-any-one-help-on-this/m-p/210287#M267366</guid>
      <dc:creator>Jbabu</dc:creator>
      <dc:date>2015-08-30T19:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc optmodel how  to use arrays can any one help on this</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-optmodel-how-to-use-arrays-can-any-one-help-on-this/m-p/224424#M267367</link>
      <description>&lt;P&gt;Answered offline via email discussion.&amp;nbsp; The final code, shown below,&amp;nbsp;did not use any macros.&amp;nbsp; Also, questions about PROC OPTMODEL in SAS/OR are better suited for the Mathematical Optimization and Operations Research Community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variables = 12;

data indata;
   input X1-X&amp;amp;variables;
   datalines;
0.1153   0.3095   0.0749   0.1320   0.1043   0.0434   0.0086   0.0225   0.0162   0.0312   0.0159   0.1261
0.1504   0.3091   0.0794   0.1308   0.0471   0.0491   0.0057   0.0199   0.0327   0.0252   0.0160   0.1344
0.2557   0.2531   0.0906   0.0932   0.0386   0.0495   0.0047   0.0180   0.0336   0.0208   0.0113   0.1308
0.2894   0.2535   0.0846   0.0447   0.0530   0.0518   0.0042   0.0177   0.0260   0.0166   0.0134   0.1451
0.2692   0.2765   0.0830   0.0259   0.0598   0.0524   0.0122   0.0184   0.0241   0.0168   0.0131   0.1486
0.3013   0.2538   0.0765   0.0297   0.0435   0.0452   0.0132   0.0186   0.0240   0.0172   0.0130   0.1642
0.3077   0.2485   0.0812   0.0437   0.0418   0.0449   0.0368   0.0201   0.0266   0.0119   0.0125   0.1245
0.2825   0.2347   0.0829   0.0779   0.0421   0.0449   0.0415   0.0253   0.0253   0.0139   0.0184   0.1105
0.2822   0.2237   0.0889   0.0509   0.0550   0.0431   0.0404   0.0246   0.0276   0.0169   0.0128   0.1338
0.3030   0.2273   0.0936   0.0718   0.0543   0.0572   0.0377   0.0302   0.0232   0.0165   0.0113   0.0737
;

proc optmodel;
   set OBS;
   num c {OBS, 1..&amp;amp;variables};
   read data indata into OBS=[_N_] {j in 1..&amp;amp;variables} &amp;lt;c[_N_,j]=col('X'||j)&amp;gt;;

   ************* step 1********************;
   set EQS = (OBS diff {1}) cross 1..&amp;amp;variables;
   var u{EQS}&amp;gt;= 0,v{EQS}&amp;gt;= 0;

   ************* step 2********************;
   var x {1..&amp;amp;variables, 1..&amp;amp;variables} &amp;gt;= 0;

   ************* step 3********************;
   min z = sum{&amp;lt;i,j&amp;gt; in EQS} u[i,j] + sum{&amp;lt;i,j&amp;gt; in eqs} v[i,j];

   ************* step 4********************;
   con Mycon {&amp;lt;i,j&amp;gt; in EQS}:
      sum {k in 1..&amp;amp;variables} c[i-1,k] * x[k,j] + u[i,j] - v[i,j] = c[i,j];

   ************* step 5********************;
   con SumToOne {i in 1..&amp;amp;variables}:
      sum {k in 1..&amp;amp;variables} x[i,k] = 1;

   solve;

   ************* step 6********************;
   print x;
   create data tm_all from [col1=i]=(1..&amp;amp;variables) {k in 1..&amp;amp;variables} &amp;lt;col('x'||k)=x[k,i]&amp;gt;;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Sep 2015 15:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-optmodel-how-to-use-arrays-can-any-one-help-on-this/m-p/224424#M267367</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2015-09-08T15:41:17Z</dc:date>
    </item>
  </channel>
</rss>

