Thanks @RobPratt for your suggestion. It works like a charm. You have been very helpful. Well appreciated! I was wondering whether we can add a constraint of max number of 'Manager' and 'Analyst' in your OPTMODEL code. For example, there are 100 high value customers (based on > 50 sale) in a particular region. We require only 34 Managers (=100/3). Suppose we have currently 50 managers in this location so customers should be allocated to max 34 Managers (not 50). It may make some customers are not allocated to the nearest manager. Same logic holds for 'Analyst' as per their customers constraint.
If I understand correctly, you want to limit the number of managers that are used. In that case, you have a p-median problem in which the managers are the facilities. Explicitly, you can replace the Cardinality constraints in the previous code with the following:
var UseManager {PORTFOLIO_MANAGERS} binary;
con Capacity {p in PORTFOLIO_MANAGERS}:
sum {<c,(p)> in CP_PAIRS} Assign[c,p]
<= (if position[p] = 'Manager' then 3 else 5) * UseManager[p];
con Cardinality:
sum {p in PORTFOLIO_MANAGERS} UseManager[p] <= 34;
Thank you so much. In this section of code "sum {p in PORTFOLIO_MANAGERS} UseManager[p] <= 34;", i was trying to calculate 34 from the customer's file. I added this code ' ceil(sum {c in customers} debt[c] / 3) ' instead of 34. But it does not work.
That syntax looks fine. Did you declare and read the debt parameter before trying to use it in the constraint?
Did you get an error message or an unexpected solution?
One way to correction your expression is to insert some parentheses:
ceil(sum {c in customers} (sales[c] > 50) / 3)
This is equivalent to any of the following:
ceil(sum {c in customers} (if sales[c] > 50 then 1 else 0) / 3)
ceil(sum {c in customers} (if sales[c] > 50 then 1) / 3)
ceil(sum {c in customers: sales[c] > 50} 1 / 3)
ceil(card({c in customers: sales[c] > 50}) / 3)
You can use the EXPAND statement to see the resulting constraint:
expand Cardinality;
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!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.