BookmarkSubscribeRSS Feed
Ksharp
Super User

It is OR question . better post it at OR forum , @RobPratt  is there .

13 REPLIES 13
jenniferl0908
Calcite | Level 5

Hi all, 

 

I need your help with coding.

I am running SAS Enterprise 7.1 Optimization part,

 

proc optmodel;
set<str> aud;

NUM CPP{aud},nar{aud},monthly_universe{aud},gp_nar{aud},ncr{aud};
READ DATA NEXT_BEST_STRATEGY into aud=[aud] monthly_universe CPP nar GP_NAR ncr;

var x{aud}>=0;
max f=sum{i in aud} x[i]*gp_nar[i];
con availability {i in aud}:
x[i]<=monthly_universe[i];
con budget:
sum{i in aud} x[i]*CPP[i] <= 1111111

solve with lp;
create data results_sas from [aud]={i in aud} nar GP_NAR ncr /*monthly_UNIVERSE*/ mailvolume=x CPP ;
run;

 

I ran above code and got below following error message 

 

max f=sum{i in aud} x[i]*gp_nar[i]

 

ERROR: A coefficient for symbol f is missing or invalid.

 

The logic of my code is as below:

1. Proc optmodel;

2. Declare sets and numerators;

3. Objective function. Max

4. Constraints.

5. Solve with LP;

6. quit;

 

I cannot find any clue from other sources for debugging this error code.

please help me and thank you so much!

ChrisNZ
Tourmaline | Level 20

Welcome to the SAS connumity.

 

Message moved to Procedures forum.

You might want to add    proc optmodel    in your title to draw in the right people.

 

Please use the running man icon to post code, and the {i} icon to post log text.

RobPratt
SAS Super FREQ

That error means that gp_nar has at least one missing value in your NEXT_BEST_STRATEGY data set.  If that is expected, how do you want to treat missing values?

 

Two other issues:

1. Your con budget statement needs a terminating semicolon.

2. Replace the RUN statement with a QUIT statement.

jenniferl0908
Calcite | Level 5

I deleted the missing value in gp_nar and reran it. it still shows the same error message.

 

RobPratt
SAS Super FREQ

Are you able to share your data?

jenniferl0908
Calcite | Level 5

sure. i attached the file.

RobPratt
SAS Super FREQ

Which column corresponds to aud?

jenniferl0908
Calcite | Level 5

combo is corresponding 

jenniferl0908
Calcite | Level 5

below is my full codes for this.

 

data work.NEXT_BEST_STRATEGY;
set NEXT_BEST_STRATEGY;
audience=trim(program)||'_'||trim(footprint)||'_'||trim(DM_GM_Decile)||'_'||trim(Zip_Code)||'_'||trim(left(cpp));
audience_2=trim(program)||'_'||trim(footprint)||'_'||trim(DM_GM_Decile)||'_'||trim(Zip_Code);
run;

 

data NEXT_BEST_STRATEGY;
set work.NEXT_BEST_STRATEGY;
proxy_ga=nar*monthly_universe;
if monthly_universe=. then delete;
if proxy_ga=0 then delete;
aud=put(Combo,$80.);
run;

 

proc optmodel;
set <str> aud;/*pulling strings ie character*/

NUM CPP{aud},nar{aud},monthly_universe{aud} ,gp_nar{aud},ncr{aud} ;
READ DATA NEXT_BEST_STRATEGY into aud=[aud] monthly_universe CPP nar GP_NAR ncr;

var x{aud}>=0;
max f=sum{i in aud} x[i]*gp_nar[i];*maximize gross adds;

con availability {i in aud}:
x[i]<=monthly_universe[i];*condition to not exceed available circ in the segment;
con budget:
sum{i in aud} x[i]*CPP[i] <=111111;
solve with lp; 
create data results_sas from [aud]={i in aud} nar GP_NAR ncr  mailvolume=x CPP ;
quit;

 

data output;
set results_sas;
where mailvolume >0;
run;

 

proc sql;
create table output as
select a.*,b.program,b.DM_GM_Decile,b.Zip_Code ,b.footprint,b.format
from output a left join NEXT_BEST_STRATEGY b
on a.aud=b.aud;
quit;

RobPratt
SAS Super FREQ

Can you please attach the data set instead of csv?

RobPratt
SAS Super FREQ

I see 49 observations with missing values for gp_nar.  The first such observation is 1147.  Here is one way to omit those observations after the READ DATA statement:

 

   aud = {i in aud: gp_nar[i] ne .};

Here is another way, using a WHERE= option:

 

 

   READ DATA NEXT_BEST_STRATEGY(where=(gp_nar ne .)) into aud=[aud] monthly_universe CPP nar GP_NAR ncr;

 

In either case, the solver executes successfully:

NOTE: Problem generation will use 4 threads.
NOTE: The problem has 6057 variables (0 free, 0 fixed).
NOTE: The problem has 6058 linear constraints (6058 LE, 0 EQ, 0 GE, 0 range).
NOTE: The problem has 12114 linear constraint coefficients.
NOTE: The problem has 0 nonlinear constraints (0 LE, 0 EQ, 0 GE, 0 range).
NOTE: The LP presolver value AUTOMATIC is applied.
NOTE: The LP presolver time is 0.03 seconds.
NOTE: The LP presolver removed 139 variables and 6057 constraints.
NOTE: The LP presolver removed 6196 constraint coefficients.
NOTE: The presolved problem has 5918 variables, 1 constraints, and 5918 constraint
      coefficients.
NOTE: The LP solver is called.
NOTE: The Dual Simplex algorithm is used.
                           Objective
      Phase Iteration        Value         Time
       D 2          1    6.032880E+03         0
       D 2          2    8.538518E+02         0
NOTE: Optimal.
NOTE: Objective = 853.85179409.
NOTE: The Dual Simplex solve time is 0.00 seconds.

 

Also, here is a correct CREATE DATA statement:

 

   create data results_sas from [aud] nar GP_NAR ncr  mailvolume=x CPP ;

 

 

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
  • 13 replies
  • 1598 views
  • 0 likes
  • 4 in conversation