Reputation: 1
I have a dataset like the following:
data have;
id=1; x1=10; x2=3; x3=5; y=220;
y1g=12; y2g=6; y3g=10;
output;
id=2; x1=7; x2=0; x3=3; y=100;
y1g=12; y2g=0; y3g=10;
output;
run;
for each record I want to had values for y1
, y2
, y3
, such that
x1*y1+x2*y2+x3*y3=y
0=<y1<=12
0=<y2<=6
0=<y3<=10
I am not sure of which can be the objective function, but to fix the ideas
I might want that the solutions are as similar as possible to some initial guess, y1g
,y2g
, y3g
.
so for instance the objective might be:
min (y1-y1g)**2+(y2-y2g)**2+(y3-y3g)**2
I am using SAS9 M5 and have to apply the program to a dataset of about 100000 records.
can you suggest me with the proc optmodel code? thank you very much in advance
Upvotes: 0
Views: 135
Reputation: 12909
Although your solution is infeasible with your constraints, this is what the optmodel code looks like:
proc optmodel;
set row;
num id;
num x1{row};
num x2{row};
num x3{row};
num y1g{row};
num y2g{row};
num y3g{row};
num y{row};
num y1sol{row};
num y2sol{row};
num y3sol{row};
var y1;
var y2;
var y3;
read data have into row=[id]
x1 x2 x3 y y1g y2g y3g
;
con con1: x1[id]*y1 + x2[id]*y2 + x3[id]*y3 = y[id];
con con2: 0 <= y1 <= 12;
con con3: 0 <= y2 <= 6;
con con4: 0 <= y3 <= 10;
min sum_squared_dif = ( (y1-y1g[id])**2+(y2-y2g[id])**2+(y3-y3g[id])**2 );
cofor {i in row} do;
id = i;
solve;
/* Save each individual solution */
y1sol[id] = y1.sol;
y2sol[id] = y2.sol;
y3sol[id] = y3.sol;
end;
print y1sol y1g y2sol y2g y3sol y3g;
quit;
Note that the first row has an infeasible solution.
Upvotes: 1