Good afternoon fellow SAS-users,
I am dealing with a non-linear problem using Proc optmodel (SAS 9.4).
I am optimizing a diet (i.e a list of foods (n=400) with their respecting daily quantities). My objective function minimizes the deviation from the initial (or "observed") diet, and a set of linear and non-linear constraints is imposed.
The variables are thus the (optimized) quantities of the 400 foods.
Here part of my code to show how I defined my variables:
set<str> foods;
/* [...] */
num qte_obs{foods}; /* this are the observed quantities (what the population currently eats) */
/* [...] */
var qte_opt{foods} >=0; /* in this case, no initialization specified */
/* [...] */
minimize deviation = sum{p in foods}(delta[p]/qte_obs[p]); /* with delta[p] defined as (qte_opt[p] - qte_obs[p])*/
/* [...] */
read data foods2 into foods=[_CODAL] qte_obs=MEAN;
/* foods2 is the table that provides the observed quantities for each food item (column MEAN), _CODAL is the ID of each food item */
I noticed that different initializations values may result in different optimal solutions.
So far I used the following syntax to initialize the variables :
var qte_opt{foods} init 3 >=0; /* 3 is just an example*/
Doing so, all the 400 quantities are initialized at 3 (3 g/day).
I would like each of the 400 variables to be initialized at a given value, i.e the observed value. The point of departure would thus be the observed diet.
I tried many syntaxes, all resulting in various errors. Here what I tried, to give you an idea of what I want :
var qte_opt{foods} init [1 ... 400] >=0; /* I exhaustively typed 400 values: from 1 to 400 (as a try, the real values would be the 400 observed values)*/
/* ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, +, -, /, IF, INPUT,
INTER, MAX, MIN, PROD, PUT, SETOF, SLICE, SUM, UNION, {.
ERROR 200-322: The symbol is not recognized and will be ignored. */
other try closer to what I want:
var qte_opt{foods} init qte_obs{foods} >=0;
/*ERROR 22-322: Syntax error, expecting one of the following: !!, (, *, **, +, -, .., /, <=, <>,
><, >=, BY, CROSS, DIFF, ELSE, INIT, INTER, SYMDIFF, TO, UNION, [, ^, ||.
ERROR 76-322: Syntax error, statement will be ignored.*/
and other unsuccessful attempts...
I am wondering if it is possible to do such an initialization, and what is the correct syntax.
Thank you,
Best regards,
T.
var qte_opt{p in foods} init qte_obs[p] >=0;
var qte_opt{p in foods} init qte_obs[p] >=0;
Perfect !
Thank you very much.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.