Hello,
Is it possible to avoid zeros in input-datasets for proc optmodel?
A simple example would look like this. In this case I would like to get rid of P1/R3, P2/R1, P3/R3 in "M_Qty".
Data A;
Input Prod $ Comp $ Qty;
Datalines;
P1 R1 0.8
P1 R2 0.2
P1 R3 0
P2 R1 0
P2 R2 0.5
P2 R3 0.5
P3 R1 0.2
P3 R2 0.8
P3 R3 0
;
Run;
Data B;
Input Comp $ Price;
Datalines;
R1 20
R2 30
R3 50
;
Run;
Proc Optmodel;
Set <Str,Str> p_c;
Num M_Qty{p_c};
Read Data A Into p_c=[Prod Comp] M_Qty=Qty;
Set Products = SetOf{<p,c> in p_c} p;
Set Components = SetOf{<p,c> in p_c} c;
Num M_Price{Components};
Read Data B Into [Comp] M_Price=Price;
Var X{Products} >=0;
Con Cns1:Sum{p in Products,c in Components} X
*M_Qty[p,c]>=5;
Con Cns2{c in Components:c="R1"}:Sum{p in Products} X
*M_Qty[p,c]>=5;
Min Obj=Sum {p in Products, c in Components} M_Qty[p,c]*M_Price
;
Solve;
Print M_Qty;
Quit;
Thanks&kind regards
You can use data set options in the READ DATA statement:
Read Data A(where=(Qty ne 0)) Into p_c=[Prod Comp] M_Qty=Qty;
And then change your constraint and objective declarations to use the sparse set p_c:
Con Cns1:Sum{<p,c> in p_c} X
*M_Qty[p,c]>=5;
Con Cns2{c in Components:c="R1"}:Sum{<p,(c)> in p_c} X
*M_Qty[p,c]>=5;
Min Obj=Sum {<p,c> in p_c} M_Qty[p,c]*M_Price
;
You can use data set options in the READ DATA statement:
Read Data A(where=(Qty ne 0)) Into p_c=[Prod Comp] M_Qty=Qty;
And then change your constraint and objective declarations to use the sparse set p_c:
Con Cns1:Sum{<p,c> in p_c} X
*M_Qty[p,c]>=5;
Con Cns2{c in Components:c="R1"}:Sum{<p,(c)> in p_c} X
*M_Qty[p,c]>=5;
Min Obj=Sum {<p,c> in p_c} M_Qty[p,c]*M_Price
;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.