BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alain38
Quartz | Level 8

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,

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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;
 

 

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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;
 

 

Alain38
Quartz | Level 8

It's working perfectly, thank you! Smiley Happy

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

Multiple Linear Regression in SAS

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.

Discussion stats
  • 2 replies
  • 810 views
  • 1 like
  • 2 in conversation