%let x= 3; are may be increas
%let eq = 300;
%macro code;
proc optmodel;
ods output printtable = TM_ALL;
var u{i in 1..&eq}>= 0,v{i in 1..&eq}>= 0,
min z = sum{i in 1..&eq} u + sum{i in 1..&eq} v;con
C1: 0.23 * x1[1] + 0.88 * x2[1] + 0.5549 * x3[1] + 0.1342 + u[1]-v[1] =0.88,
like upt0 300 c1 to c300 constraints are there how to use here loops are arrays any suggestion on my code. help on this
i tried another example i got but i have use calculation like
%do z = 1 %to &variables;
sum {i in 1..&variables} x&z.=1
%If &z. < &variables %then %let com1 =,;
%else %let com1 = ; &com1.
%end;;
solve;
%do z=1 %to &variables;
x&z %end;;
quit;
%mend;
%code;
Answered offline via email discussion. The final code, shown below, did not use any macros. Also, questions about PROC OPTMODEL in SAS/OR are better suited for the Mathematical Optimization and Operations Research Community.
%let variables = 12;
data indata;
input X1-X&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..&variables};
read data indata into OBS=[_N_] {j in 1..&variables} <c[_N_,j]=col('X'||j)>;
************* step 1********************;
set EQS = (OBS diff {1}) cross 1..&variables;
var u{EQS}>= 0,v{EQS}>= 0;
************* step 2********************;
var x {1..&variables, 1..&variables} >= 0;
************* step 3********************;
min z = sum{<i,j> in EQS} u[i,j] + sum{<i,j> in eqs} v[i,j];
************* step 4********************;
con Mycon {<i,j> in EQS}:
sum {k in 1..&variables} c[i-1,k] * x[k,j] + u[i,j] - v[i,j] = c[i,j];
************* step 5********************;
con SumToOne {i in 1..&variables}:
sum {k in 1..&variables} x[i,k] = 1;
solve;
************* step 6********************;
print x;
create data tm_all from [col1=i]=(1..&variables) {k in 1..&variables} <col('x'||k)=x[k,i]>;
quit;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.