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];

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 813 views
  • 0 likes
  • 2 in conversation