BookmarkSubscribeRSS Feed
qkaiwei
Calcite | Level 5

A question about constraint statement of optmodel  procedure, sum of elements in array x must be less or equal to 100, and number of elements greater than 0 must be less or equal to 3, I don't know how to write this properly. 

 

Thanks!

 

proc optmodel:

set<number> dates=1..10;

var x{dates} >=0 init 0;

......

con c1: sum{i in dates} x[i] <=100;

con c2: sum{i in dates}  /*(x[i]>0)*/  <= 3;

quit;

 

 

1 REPLY 1
RobPratt
SAS Super FREQ

Introduce a binary variable y[i] that is 1 if x[i] > 0:

   var x{dates} >=0 init 0 <= 100;
   con c1: sum{i in dates} x[i] <=100;
   var y{dates} binary;
   con c2: sum{i in dates} y[i] <= 3;
   con c3 {i in dates}: x[i] <= x[i].ub * y[i];

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
  • 1 reply
  • 769 views
  • 0 likes
  • 2 in conversation