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

hi,

I am trying to solve the following problem

Capture.JPG

 

 

and I have written the following code:

proc optmodel;
var x{1..3};
minimize f = x[1] - 2*x[2] + 4*x[3] + x[1]**2 + 2*x[2]**2 + 3*x[3]**2 + x[1]*x[2];

con r1: 3*x[1] + 4*x[2] -2*x[3] <= 10;
con r2: -3*x[1] + 2*x[2] + x[3] >= 2;
con r3: 2*x[1] + 3*x[2] + 4*x[3] =5;
con r4: x[1] <=5;
con r5: x[2] <=5;
con r6: x[3] <=5;
con r7: x[1] >=0;
con r8: x[2] >=0;
con r9: x[3] >=0; solve with qp; print x; save qps qpsdata; quit;

Please tell me if I am doing it right.Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

Your code looks correct to me, but you can do it a little more simply by omitting the SAVE QPS statement and the WITH QP clause and by including the bounds in the VAR statement:

proc optmodel;
   var x{1..3} >= 0 <= 5;
   minimize f = x[1] - 2*x[2] + 4*x[3] + x[1]**2 + 2*x[2]**2 + 3*x[3]**2 + x[1]*x[2];

   con r1: 3*x[1] + 4*x[2] -2*x[3] <= 10;
   con r2: -3*x[1] + 2*x[2] + x[3] >= 2;
   con r3: 2*x[1] + 3*x[2] + 4*x[3] =5;
   solve;
   print x;
quit;

By using the EXPAND / SOLVE statement, you can see that both versions pass the same formulation to the solver.

View solution in original post

1 REPLY 1
RobPratt
SAS Super FREQ

Your code looks correct to me, but you can do it a little more simply by omitting the SAVE QPS statement and the WITH QP clause and by including the bounds in the VAR statement:

proc optmodel;
   var x{1..3} >= 0 <= 5;
   minimize f = x[1] - 2*x[2] + 4*x[3] + x[1]**2 + 2*x[2]**2 + 3*x[3]**2 + x[1]*x[2];

   con r1: 3*x[1] + 4*x[2] -2*x[3] <= 10;
   con r2: -3*x[1] + 2*x[2] + x[3] >= 2;
   con r3: 2*x[1] + 3*x[2] + 4*x[3] =5;
   solve;
   print x;
quit;

By using the EXPAND / SOLVE statement, you can see that both versions pass the same formulation to the solver.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 584 views
  • 1 like
  • 2 in conversation