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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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