## Avoid zeros in input-data

Solved
Super Contributor
Posts: 346

# Avoid zeros in input-data

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 Cns1um{p in Products,c in Components} X

*M_Qty[p,c]>=5;
Con Cns2{c in Components:c="R1"}um{p in Products} X

*M_Qty[p,c]>=5;
Min Obj=Sum {p in Products, c in Components} M_Qty[p,c]*M_Price*X

;
Solve;
Print M_Qty;
Quit;

Thanks&kind regards

Accepted Solutions
Solution
‎07-15-2015 09:15 AM
SAS Employee
Posts: 538

## Re: Avoid zeros in input-data

Posted in reply to user24feb

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 Cns1um{<p,c> in p_c} X

*M_Qty[p,c]>=5;

Con Cns2{c in Components:c="R1"}um{<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*X

;

All Replies
Solution
‎07-15-2015 09:15 AM
SAS Employee
Posts: 538

## Re: Avoid zeros in input-data

Posted in reply to user24feb

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 Cns1um{<p,c> in p_c} X

*M_Qty[p,c]>=5;

Con Cns2{c in Components:c="R1"}um{<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*X

;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats