I am trying to find the optimal two products out of three (A,B,C) that maximizes total market penetration (i.e. unduplicated reach) in a specific market. The data below is an abbreviated example with just four subjects (01, 02, 03, 04) and three products (A,B,C).
The current program maximizes the penetration of each of the products separately (choosing A and B as the decision vars that maximize the obj. function). However I need to maximize the market penetration as a whole. A & B only provide a total market penetration of 75%, whereas A & C provide a total market penetration of 100%. I'm having difficulty converting my program from individual to total market penetration. Still being relatively new to OPTMODEL, any help you can provide is very much appreciated.
data byPROD;
input Product $ ;
datalines;
A
B
C
;
run;
data byID;
input unID $ A B C;
datalines;
01 1 1 0
02 1 1 0
03 1 0 0
04 0 0 1
;
run;
proc optmodel;
set <str> ID, PRODUCTS;
num units {ID,PRODUCTS};
read data byPROD into PRODUCTS=[Product];
read data byID into ID=[unID] {p in PRODUCTS} <units[unID,p]=col(p)>;
num ProdSum{p in PRODUCTS}=sum{i in ID} units[i,p];
var Subset{PRODUCTS} >=0 binary;
max MktPenetration=sum{p in PRODUCTS} ProdSum[p]*Subset[p];
con OnlyTwo: sum{p in PRODUCTS} Subset[p]=2;
solve;
print Subset;
quit;
You can introduce another binary variable IsCovered for each subject, a constraint that links IsCovered to Subset, and a new expression for the objective:
var IsCovered{ID} binary;
/* if IsCovered[i] = 1 then Subset[p] = 1 for some p with units[i,p] > 0 */
con IsCoveredCon {i in ID}:
IsCovered[i] <= sum {p in PRODUCTS: units[i,p] > 0} Subset[p];
max MktPenetration=sum{i in ID} IsCovered[i];
You can introduce another binary variable IsCovered for each subject, a constraint that links IsCovered to Subset, and a new expression for the objective:
var IsCovered{ID} binary;
/* if IsCovered[i] = 1 then Subset[p] = 1 for some p with units[i,p] > 0 */
con IsCoveredCon {i in ID}:
IsCovered[i] <= sum {p in PRODUCTS: units[i,p] > 0} Subset[p];
max MktPenetration=sum{i in ID} IsCovered[i];
Wow, thank you for the quick response, Rob. Your addition was a major help. If in the byID data set I change row 03 column B to 1 from 0 (in code below), then both A&C and B&C provide 100% total market penetration.
data byID;
input unID $ A B C;
datalines;
01 1 1 0
02 1 1 0
03 1 1 0
04 0 0 1
;
run;
The updated OPTMODEL program chooses A&C as the optimal pair. Is there a way to show all combinations if more than one combination shares the optimal value?
Yes, you can use the FINDALLSOLNS option with the CLP solver:
solve with clp / findallsolns;
for {s in 1.._NSOL_} print {p in PRODUCTS} Subset[p].sol[s];
You might also be interested in this SAS Global Forum 2016 paper:
http://support.sas.com/resources/papers/proceedings16/SAS3161-2016.pdf
Thanks, that's exactly what I was looking to do. Unfortunately I'm getting an error in my log (below). I'm running PROC OPTMODEL in SAS EG 5.1, and your paper mentions the 'solve with CLP' option was released with SAS/OR 13.2, so it appears that I'm calling a pre-13.2 version of SAS/OR in EG. Do you know if that is the case?
Nevertheless, thank you for your time. This has been a huge help!
57 solve with CLP / findallsolns;
___
585
ERROR 585-782: Solver 'CLP' is unknown.
58
59 for {s in 1.._NSOL_} print {p in PRODUCTS} Subset[p].sol[s];
______ _
537 22
ERROR 537-782: The symbol '_NSOL_' is unknown.
ERROR 22-322: Expecting a name.
60
61 *solve;
Yes, it looks like you are running an old version of SAS/OR. You can see which version by submitting the following code:
proc product_status;
run;
Even SAS/OR 13.2 is three years old, with two additional releases (14.1 and 14.2) since then. Also, SAS/OR 14.3 is coming out very soon!
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!
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.