Calcite | Level 5

ERROR: An objective coefficient is missing or invalid.

Hello,

I can't figure out why this code runs fine with data A, but not with data B. Thank you for your help.

``````PROC SQL NOPRINT;
SELECT t1.MAX_of_i, t1.MAX_of_p, t1.MAX_of_f, t1.MAX_of_r INTO
:max_i, :max_p, :max_f, :max_r FROM work.base t1;
QUIT;

proc optmodel;
set i_RANGE = 0..&max_i.;
set p_RANGE = 0..&max_p.;
set f_RANGE = 0..&max_f.;
set r_RANGE = 0..&max_r.;
num v{1..%eval((&max_i + 1) *(&max_p + 1) * (&max_f + 1) * (&max_r +1))};
num u{1..%eval((&max_i + 1) *(&max_p + 1) * (&max_f + 1) * (&max_r +1))};
num isReal{1..%eval((&max_i + 1) *(&max_p + 1) * (&max_f + 1) * (&max_r +1))};
num a_v{0..&max_i, 0..&max_p, 0..&max_f, 0..&max_r};
num w_v{0..&max_i, 0..&max_p, 0..&max_f, 0..&max_r};
var e_v{i_RANGE, p_RANGE, f_RANGE, r_RANGE} >= 0;
read data WORK.DS_IN into [_n_] isReal v u;

/*reshape data*/
num ind;
num ii;
num ip;
num fi;
num ir;
ind = 1;

do ii = 0 to &max_i.;
do ip = 0 to &max_p.;
do fi = 0 to &max_f.;
do ir = 0 to &max_r.;
a_v[ii,ip,fi,ir] = v[ind];
e_v[ii,ip,fi,ir] = u[ind];
w_v[ii,ip,fi,ir] = isReal[ind];;
ind = ind + 1;
end;
end;
end;
end;

min e =
/* retain its original value as much as possible*/
(

sum{i in 0..&max_i., p in 0..&max_p., f in 0..&max_f.,r in 0..&max_r.}
(9*w_v[i,p,f,r]+1)*
(((e_v[i,p,f,r] - a_v[i,p,f,r])/(10 + a_v[i,p,f,r]) * 1000)**2)  +

sum{i in 0..&max_i., p in 0..&max_p., f in 0..&max_f.,r in 0..&max_r.}(9*w_v[i,p,f,r]+1)*((e_v[i,p,f,r] - a_v[i,p,f,r])**2) / 1000 +

sum{i in 0..&max_i.} (9*w_v[i,0,0,0]+1)*(a_v[i,0,0,0] - (sum{p in 1..&max_p.}e_v[i,p,0,0])) ** 2  +
sum{i in 0..&max_i.} (9*w_v[i,0,0,0]+1)*(a_v[i,0,0,0] - (sum{f in 1..&max_f.}e_v[i,0,f,0])) ** 2  +
sum{i in 0..&max_i.} (9*w_v[i,0,0,0]+1)*(a_v[i,0,0,0] - (sum{r in 1..&max_r.}e_v[i,0,0,r])) ** 2  +

sum{i in 0..&max_i., f in 0..&max_f.} (9*w_v[i,0,f,0]+1)*(a_v[i,0,f,0] - (sum{p in 1..&max_p.}e_v[i,p,f,0])) ** 2 +
sum{i in 0..&max_i., f in 0..&max_f.} (9*w_v[i,0,f,0]+1)*(a_v[i,0,f,0] - (sum{r in 1..&max_r.}e_v[i,0,f,r])) ** 2 +

sum{i in 0..&max_i., p in 0..&max_p.} (9*w_v[i,p,0,0]+1)*(a_v[i,p,0,0] - (sum{f in 1..&max_f.}e_v[i,p,f,0])) ** 2 +
sum{i in 0..&max_i., p in 0..&max_p.} (9*w_v[i,p,0,0]+1)*(a_v[i,p,0,0] - (sum{r in 1..&max_r.}e_v[i,p,0,r])) ** 2 +

sum{i in 0..&max_i., r in 0..&max_r.} (9*w_v[i,0,0,r]+1)*(a_v[i,0,0,r] - (sum{p in 1..&max_p.}e_v[i,p,0,r])) ** 2 +
sum{i in 0..&max_i., r in 0..&max_r.} (9*w_v[i,0,0,r]+1)*(a_v[i,0,0,r] - (sum{f in 1..&max_f.}e_v[i,0,f,r])) ** 2 +

sum{i in 0..&max_i., f in 0..&max_f.} (9*w_v[i,0,f,0]+1)*((a_v[i,0,f,0] - (sum{p in 1..&max_p.}e_v[i,p,f,0]))/(100+a_v[i,0,f,0])*1000) ** 2 +
sum{i in 0..&max_i., f in 0..&max_f.} (9*w_v[i,0,f,0]+1)*((a_v[i,0,f,0] - (sum{r in 1..&max_r.}e_v[i,0,f,r]))/(100+a_v[i,0,f,0])*1000) ** 2 +

sum{i in 0..&max_i., p in 0..&max_p.} (9*w_v[i,p,0,0]+1)*((a_v[i,p,0,0] - (sum{f in 1..&max_f.}e_v[i,p,f,0]))/(100+a_v[i,p,0,0])*1000) ** 2 +
sum{i in 0..&max_i., p in 0..&max_p.} (9*w_v[i,p,0,0]+1)*((a_v[i,p,0,0] - (sum{r in 1..&max_r.}e_v[i,p,0,r]))/(100+a_v[i,p,0,0])*1000) ** 2 +

sum{i in 0..&max_i., r in 0..&max_r.} (9*w_v[i,0,0,r]+1)*((a_v[i,0,0,r] - (sum{p in 1..&max_p.}e_v[i,p,0,r]))/(100+a_v[i,0,0,r])*1000) ** 2 +
sum{i in 0..&max_i., r in 0..&max_r.} (9*w_v[i,0,0,r]+1)*((a_v[i,0,0,r] - (sum{f in 1..&max_f.}e_v[i,0,f,r]))/(100+a_v[i,0,0,r])*1000) ** 2 +

%if (&hasVarSum. > 0) %then %do;
sum{p in 1..&max_p., f in 1..&max_f.} (9*w_v[0,p,f,0]+1)*(a_v[0,p,f,0] - (sum{i in 1..&max_i.}e_v[i,p,f,0])) ** 2 +
sum{p in 1..&max_p., r in 1..&max_r.} (9*w_v[0,p,0,r]+1)*(a_v[0,p,0,r] - (sum{i in 1..&max_i.}e_v[i,p,0,r])) ** 2 +
sum{f in 1..&max_f., r in 1..&max_r.} (9*w_v[0,0,f,r]+1)*(a_v[0,0,f,r] - (sum{i in 1..&max_i.}e_v[i,0,f,r])) ** 2 +
sum{p in 0..&max_p.} (9*w_v[0,p,0,0]+1)*(a_v[0,p,0,0] - (sum{i in 1..&max_i.}e_v[i,p,0,0])) ** 2 +
sum{f in 0..&max_f.} (9*w_v[0,0,f,0]+1)*(a_v[0,0,f,0] - (sum{i in 1..&max_i.}e_v[i,0,f,0])) ** 2 +
sum{r in 0..&max_r.} (9*w_v[0,0,0,r]+1)*(a_v[0,0,0,r] - (sum{i in 1..&max_i.}e_v[i,0,0,r])) ** 2 +
%end;

sum{i in 0..&max_i.,p in 1..&max_p., f in 1..&max_f.} (9*w_v[i,p,f,0]+1)*(a_v[i,p,f,0]-(sum{r in 1..&max_r.}e_v[i,p,f,r])) ** 2 +
sum{i in 0..&max_i.,p in 1..&max_p., r in 1..&max_r.} (9*w_v[i,p,0,r]+1)*(a_v[i,p,0,r]-(sum{f in 1..&max_f.}e_v[i,p,f,r])) ** 2 +
sum{i in 0..&max_i.,f in 1..&max_f., r in 1..&max_r.} (9*w_v[i,0,f,r]+1)*(a_v[i,0,f,r]-(sum{p in 1..&max_p.}e_v[i,p,f,r])) ** 2 +

sum{i in 0..&max_i.,p in 1..&max_p., f in 1..&max_f.} (9*w_v[i,p,f,0]+1)*((a_v[i,p,f,0]-(sum{r in 1..&max_r.}e_v[i,p,f,r]))/(10+a_v[i,p,f,0])*1000) ** 2 +
sum{i in 0..&max_i.,p in 1..&max_p., r in 1..&max_r.} (9*w_v[i,p,0,r]+1)*((a_v[i,p,0,r]-(sum{f in 1..&max_f.}e_v[i,p,f,r]))/(10+a_v[i,p,0,r])*1000) ** 2 +
sum{i in 0..&max_i.,f in 1..&max_f., r in 1..&max_r.} (9*w_v[i,0,f,r]+1)*((a_v[i,0,f,r]-(sum{p in 1..&max_p.}e_v[i,p,f,r]))/(10+a_v[i,0,f,r])*1000) ** 2 +

sum{i in 0..&max_i.,p in 1..&max_p.} (9*w_v[i,p,0,0]+1)*(a_v[i,p,0,0]-(sum{f in 1..&max_f., r in 1..&max_r.}e_v[i,p,f,r])) ** 2 +
sum{i in 0..&max_i.,r in 1..&max_r.} (9*w_v[i,0,0,r]+1)*(a_v[i,0,0,r]-(sum{p in 1..&max_p., f in 1..&max_f.}e_v[i,p,f,r])) ** 2 +
sum{i in 0..&max_i.,f in 1..&max_f.} (9*w_v[i,0,f,0]+1)*(a_v[i,0,f,0]-(sum{p in 1..&max_p., r in 1..&max_r.}e_v[i,p,f,r])) ** 2

);

solve;

create data DS_out_test from [i p f r]={i_RANGE, p_RANGE, f_RANGE, r_RANGE} est = e_v actual = a_v isReal = w_v;
QUIT;``````
2 REPLIES 2
Super User

Re: ERROR: An objective coefficient is missing or invalid.

With any ERROR you will likely get a better answer providing the code and all the messages from the procedure or data step that generated the log.

As it is you have posted around 80 line of code, any of which could be generating the error(s) with no idea of the actual error in relation to the code submitted.

No idea where the macro variable

``&hasVarSum``

might be set or the value.

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

SAS Super FREQ

Re: ERROR: An objective coefficient is missing or invalid.

This turns out to be a division by zero in this first part of your objective function:

``````         sum{i in 0..&max_i., p in 0..&max_p., f in 0..&max_f.,r in 0..&max_r.}
(9*w_v[i,p,f,r]+1)*
(((e_v[i,p,f,r] - a_v[i,p,f,r])/(10 + a_v[i,p,f,r]) * 1000)**2)  +
``````

For data B, the value of `a_v[8,10,3,7]` is -10, yielding a zero denominator.

Discussion stats
• 2 replies
• 711 views
• 0 likes
• 3 in conversation