Hello,
Is it possible to save in a dataset the solution status of proc optmodel?
I'm indeed running thousands of optimization problems such as:
%let byvar = grp;
proc optmodel printlevel=0;
set OBS;
set <str> ASSETS;
set <num,str> GROUPS_ASSETS;
set GROUPS;
num grp{OBS};
num MVC{GROUPS_ASSETS, ASSETS};
num E{GROUPS_ASSETS};
num target_var{GROUPS};
read data MVC into ASSETS=[Name];
read data MVC into OBS=[_N_] grp;
read data MVC nomiss into GROUPS_ASSETS=[k=grp i=Name] {j in ASSETS} <MVC[k,i,j]=col(j)>;
read data Predicted nomiss into [k=grp] {j in ASSETS} <E[k,j]=col(j)>;
read data Target_Var into GROUPS=[grp] target_var;
set BYSET = setof {i in OBS} &byvar.[i];
num by;
set OBS_BY = {i in OBS: &byvar.[i] = by};
set Assets_BY = setof {o in OBS_BY, <(grp[o]),a> in GROUPS_ASSETS} a;
var W{Assets} >= 0;
maximize Expected = sum{i in Assets_BY}W[i]*E[by,i];
con sum{i in Assets_BY, j in Assets_BY}W[i]*MVC[by,i,j]*W[j] = target_var[by];
con BUDGET: sum{i in Assets_BY}W[i] = 1;
num W_sol {GROUPS_ASSETS};
do by = BYSET;
put by=;
solve with NLP / feastol = 1E-7 logfreq = 0 maxiter = 10000;
for {i in Assets_BY} W_sol[by,i] = W[i].sol;
end;
create data Weights_NoShort from [&byvar i] W=W_sol;
quit;
However, I noticed that in a few cases, the NOTE in the log is not "Optimal" but:
- NOTE: Maximum number of iterations reached
- NOTE: Infeasible
Saving them in a dataset would allow me to quickly check which by group did not solve correctly.
Thank you in advance,
Yes, you can use the _solution_status_ parameter:
num W_sol {GROUPS_ASSETS};
str solstatus {BYSET};
do by = BYSET;
put by=;
solve with NLP / feastol = 1E-7 logfreq = 0 maxiter = 10000;
for {i in Assets_BY} W_sol[by,i] = W[i].sol;
solstatus[by] = _solution_status_;
end;
create data Weights_NoShort from [&byvar i] W=W_sol;
create data solstatusdata from [&byvar] solstatus;
Yes, you can use the _solution_status_ parameter:
num W_sol {GROUPS_ASSETS};
str solstatus {BYSET};
do by = BYSET;
put by=;
solve with NLP / feastol = 1E-7 logfreq = 0 maxiter = 10000;
for {i in Assets_BY} W_sol[by,i] = W[i].sol;
solstatus[by] = _solution_status_;
end;
create data Weights_NoShort from [&byvar i] W=W_sol;
create data solstatusdata from [&byvar] solstatus;
It's working perfectly, thank you!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.