BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
user24feb
Barite | Level 11

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*X

;
  Solve;
  Print M_Qty;
Quit;

Thanks&kind regards

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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*X

;

View solution in original post

1 REPLY 1
RobPratt
SAS Super FREQ

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*X

;

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