BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
toddkirk
Calcite | Level 5

Hi All.

 

We have some old code that is now running into memory issues.  I need to move it to PROC OPTMODEL in SAS 9.4 for Windows  ... something I have wanted to do for ages.   Now, I am thankfully being forced.  The code is pretty simple:

 

proc nlp data=singlerow
tech=QUANEW update=DDFP lis=5 maxfu=5000 maxit=50000
out=solution noprint;

 

array s[&n] s1-s&n;
array r[&n] r1-r&n;
array c[&n] c1-c&n;
array x[&n] x1-x&n;
array y[&n] y1-y&n;

 

max ty;

parms c1-c&n=1;
bounds 0.8<=c1-c&n<=1.2;
nlincon tx=10000;

 

do i=1 to &n;

 

x[i]=s[i]*c[i];
y[i]=x[i]*r[i];

 

end;

 

ts=sum(of s1-s&n);
tx=sum(of x1-x&n);
ty=sum(of y1-y&n);

 

run;

 

Basically, we are shift the allocation "s" spend for a number of different investments based on their "r" immediate rate of return.  The input data "singlerow" is actually just one row of s1-s&n and r1-r&n.  The &n that is killing PROC NLP is currently 5000 different investments.

 

The goal is to get a "c"  change to each spend.  There is a change limit of +/-20% and the total "budget" must be $10,000.

 

Does anybody have a quick translation to PROC OPTMODEL that I can use to learn? 

 

Thanks in advance!

 

Will 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

The following PROC OPTMODEL code should do what you want:

proc optmodel;
   num s {1..&n};
   num r {1..&n};
   read data singlerow into
      {i in 1..&n} <s[i]=col('s'||i)>
      {i in 1..&n} <r[i]=col('r'||i)>
   ;

   var c {1..&n} init 1 >= 0.8 <= 1.2;
   impvar x {i in 1..&n} = s[i]*c[i];
   impvar y {i in 1..&n} = x[i]*r[i];

   max ty = sum {i in 1..&n} y[i];

   con Budget:
      sum {i in 1..&n} x[i] = 10000;

   solve;

   create data solution from [i] c;
quit;

You might also find the following links useful:

PROC NLP: Rewriting NLP Models for PROC OPTMODEL - 9.3 (sas.com)

41671 - Migrating from PROC NLP to PROC OPTMODEL (sas.com)

242-2010: Nonlinear Optimization in SAS/OR®: Migrating from PROC NLP to PROC OPTMODEL

View solution in original post

4 REPLIES 4
RobPratt
SAS Super FREQ

The following PROC OPTMODEL code should do what you want:

proc optmodel;
   num s {1..&n};
   num r {1..&n};
   read data singlerow into
      {i in 1..&n} <s[i]=col('s'||i)>
      {i in 1..&n} <r[i]=col('r'||i)>
   ;

   var c {1..&n} init 1 >= 0.8 <= 1.2;
   impvar x {i in 1..&n} = s[i]*c[i];
   impvar y {i in 1..&n} = x[i]*r[i];

   max ty = sum {i in 1..&n} y[i];

   con Budget:
      sum {i in 1..&n} x[i] = 10000;

   solve;

   create data solution from [i] c;
quit;

You might also find the following links useful:

PROC NLP: Rewriting NLP Models for PROC OPTMODEL - 9.3 (sas.com)

41671 - Migrating from PROC NLP to PROC OPTMODEL (sas.com)

242-2010: Nonlinear Optimization in SAS/OR®: Migrating from PROC NLP to PROC OPTMODEL

toddkirk
Calcite | Level 5

WONDERFUL! 

 

Thanks so much Rob.  This was perfect in two ways.  The first is that is absolutely works as expected.  The second that this is really easy for me to understand and think about how I update some of the other legacy PROC NLP code.  I really appreciate you sorting this out so fast.

 

Cheers


Will

RobPratt
SAS Super FREQ

Glad to help.  Notice that the objective and constraint are both linear and the variables are continuous, so OPTMODEL will by default use the linear programming (LP) solver.

toddkirk
Calcite | Level 5

Great points!  Thanks Rob!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 905 views
  • 2 likes
  • 2 in conversation