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

 

I have this problem and its works ok, but it´s possible read paramerts in data statement?

 

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   con c1: -1<=x[1]<= 3;
   con c2: 1.5<=x[2]<= 2;
   con c3: 1.2<=x[3]<= 2.2;
   solve with nlp/multistart ;
   print x;
quit;



 Edit: I want to put in data statement:

 

 

-1<=x[1]<= 3;...
1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ
data bounds;
   input lb ub;
   datalines;
-1   3
 1.5 2
 1.2 2.2
;

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub;
   solve with nlp/multistart ;
   print x;
quit;

View solution in original post

5 REPLIES 5
RobPratt
SAS Super FREQ
data bounds;
   input lb ub;
   datalines;
-1   3
 1.5 2
 1.2 2.2
;

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub;
   solve with nlp/multistart ;
   print x;
quit;
dali74
Fluorite | Level 6

if it will be possible to read coeficientes that multiplies x too? 

 

 

 

RobPratt
SAS Super FREQ
data bounds;
   input lb ub a b;
   datalines;
-1   3    2 1
 1.5 2   -3 5
 1.2 2.2  5 1
;

proc optmodel;
   var x {1..3};
   num a {1..3};
   num b {1..3};
   max z1 = (sum {j in 1..3} a[j]*x[j])**3/(b[1]*x[1]+b[2]*x[2]+b[3]*x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;
dali74
Fluorite | Level 6

edit: it works too

 

thanks rob!

 

 



data bounds;
   input lb ub a b;
   datalines;
-1   3    2 1
 1.5 2   -3 5
 1.2 2.2  5 1
;

proc optmodel;
   var x {1..3};
   num a {1..3};
   num b {1..3};
   max z1 = (sum {j in 1..3} a[j]*x[j])**3/ (sum {j in 1..3} b[j]*x[j]);
   read data bounds into [_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;
RobPratt
SAS Super FREQ

Note that your original objective function had x[3]**2 in the denominator.  With your latest change, it is now just x[3].  If that is what you want, here's a way to make the code more data-driven (without hard-coding 1..3):

proc optmodel;
   set OBS;
   var x {OBS};
   num a {OBS};
   num b {OBS};
   max z1 = (sum {j in OBS} a[j]*x[j])**3/ (sum {j in OBS} b[j]*x[j]);
   read data bounds into OBS=[_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;

This way, you can run again with different data without changing the PROC OPTMODEL code.  Such separation of model and data is a best practice enabled by the use of an algebraic modeling language.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1107 views
  • 0 likes
  • 2 in conversation