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

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,





Accepted Solutions
var qte_opt{p in foods} init qte_obs[p] >=0; 

View solution in original post

var qte_opt{p in foods} init qte_obs[p] >=0; 
Calcite | Level 5

Perfect !

Thank you very much.


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


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
  • 2 replies
  • 2 in conversation