### Table of Contents

- Preliminary Remarks
- Resolving Common Compilation Errors
- Error A: Misplaced Semicolons
- Error B: Missing Semicolons
- Error C: Spelling Mistakes
- Error D: Missing Set Elements
- Error E: Problems with Indices
- Error F: Summing over Sets that are Already Indexed
- Error G: Uncontrolled Sets
- Error H: Mismatched Parentheses
- Error I: Mistakes Relating to Equations
- Error J: Issues with Nonlinear Expressions
- Error K: Using Undefined Data
- Error L: Referencing Set Elements Without Quotes
- Error M: Missing Declaration Statements
- Error N: Using the Same Name for Different Identifiers
- Error O: Using ORD with an Unordered Set

As detailed in chapter GAMS Output, the execution of a GAMS program passes through several stages, where the *compilation* is the first stage. Often when a program is run for the first time, it cannot be solved successfully because of compilation errors. This can be very frustrating, especially for new users. In this tutorial we will explain the causes of the most common compilation errors and offer some advice on how to fix them. For an introduction to compilation errors, see section Compilation Errors. In addition, the tutorial A GAMS Tutorial by Richard E. Rosenthal offers some detailed material on this topic.

- Note
- Frequently, many compilation errors in the latter part of the code are actually consequential errors that will disappear as soon as the compilation errors in the beginning have been resolved. Therefore we recommend to start with fixing the first few errors and to run the program again. More often than not, many subsequent compilation errors will have vanished.

# Preliminary Remarks

Before we will turn to an overview of the most common errors, examples that illustrate them and advice how to resolve them, we will provide some basic information on compilation errors and error messages.

## Finding Compilation Errors

Compilation errors are marked with four asterisks (`****`

) in the compilation output of the GAMS listing file (also called output file or lst file, since it has the extension `.lst`

), hence it is easy to detect lines where compilation errors occured by inspection.

- Note
- Compilation error messages also appear in the LOG file. And, if GAMS Studio is used, a click at an error message in the LOG will navigate directly to the problematic code in the source file.

Consider the following simple example:

```
Set c "crops" / barley, wheat, soy, wheat, rice /;
```

If this set statement appears in a program, the resulting compilation output will contain the following lines:

1 Set c "crops" / barley, wheat, soy, wheat, rice /; **** $172 ... Error Messages 172 Element is redefined

Note that in the echo print of the input file a line starting with `****`

is inserted and the dollar sign `$`

followed by a number appears on this line. This indicates that a compilation error - in this case error `172`

- was discovered in the line above. In addition, a list of all errors with explanatory error messages is given at the end of the echo print.

In our example, the error refers to `wheat`

and the error message addresses the cause of the error: the respective element is redefined. Thus we check the other elements of the set and quickly realize that `wheat`

appears a second time. If we delete the second instance of `wheat`

and run the code again, this line will not cause any errors anymore. Note that many compilation errors are as easy to fix as demonstrated here.

## Repositioning Compilation Error Messages

By default, the error messages are shown directly beneath the line where the respective error is marked. GAMS allows to customize this position with the command line parameter ErrMsg: the value of 0 for `ErrMsg`

will list all error messages at the end of the echo print and the value of 2 will suppress the error messages in the lst file completely. Note that the default is 1.

Consider the following simple example.

```
Set a / a1 * a7 /;
Set b(a) / a7 * a9 /;
Parameter p(k) / i3 47 /;
```

The resulting compilation output will contain the following lines:

1 Set a / a1 * a7 /; 2 Set b(a) / a7 * a9 /; **** $170 **** 170 Domain violation for element 3 Parameter p(k) / i3 47 /; **** $120 **** 120 Unknown identifier entered as set

Observe that the error messages are placed on the line after the error is marked. This can be especially useful if the program contains many lines of code. Next, we run the same code with the following call:

> gams test ErrMsg=0

The resulting compilaton output follows.

1 Set a / a1 * a7 /; 2 Set b(a) / a7 * a9 /; **** $170 3 Parameter p(k) / i3 47 /; **** $120 ... Error Messages 120 Unknown identifier entered as set 170 Domain violation for element

Now the error messages are displayed at the end of the compiler listing.

- Note
- Default values for command line parameters and environment variables can be specified using a configuration file gamsconfig.yaml. The GAMS Configuration Editor can be used to view and edit the GAMS configuration file but any other text editor can be used as well. Alternatively, users may change the system level defaults by entering the line
`ErrMsg=0`

in the file`gmsprmnt.txt`

on Windows, or`gmsprmun.txt`

on Unix machines as in the following example:

***************************************************** * GAMS 2.50 Default Parameterfile for Windows NT * * Gams Development Corp. * * Date : 20 Mar, 1998 * ***************************************************** * entries required by CMEX, put in by gams.exe: * SYSDIR * SCRDIR * SCRIPTNEXT * INPUT errmsg=0

# Resolving Common Compilation Errors

There are hundreds of compilation errors in GAMS, but some of them are particularly frequent. In the table below we present these common errors, with a brief description of the possible cause and a link to a subsection below where examples and more details are given. We recommend that users also read the error messages, since they often contain additional hints.

GAMS Error | Common Cause of Error | Subsections with Examples and More Details |
---|---|---|

`8` | Closing parentheses, square brackets or braces are missing. | H |

`36` | The two dots `..` are missing in the equation definition. | I |

`37` | The equation type (eg. `=L=` ) is missing in the body of the equation. | I |

`51-60` | There are prohibited nonlinear expressions. | J |

`66` | A data item which has not been given numerical values appears in an equation. | K |

`71` | The equation has been declared, but not defined. | I |

`96` , `97` | A statement followed by another statement is not terminated with `;` . | B |

`120` | GAMS cannot find a set with this name. Check for typos in the set name and set elements that are referenced without quotes. | C, L |

`125` | The set is controlled more than once, e.g., by an indexed operation like `sum` and by an equation definition. | F |

`140` | GAMS is looking for a keyword or declared item and cannot find it. Check spelling and declarations. | A, C, K, M |

`141` | The parameter without data is used or problems with `solve` and therefore attributes `.l` and `.m` are empty. | K |

`148` | The identifier is referenced with more or less indexed sets than in the declaration. | E |

`149` | The set is not controlled, neither by an indexed operation like `sum` , nor by an equation definition, nor by a loop or similar. | G, L |

`170` | The referenced set element cannot be found in the set defined for this index position. Check for typos, omissions in the set declaration, missing quotes and references to the wrong set. | C, D |

`171` | A domain error. The wrong set is referenced for the respective index position. | E, L |

`195` | The name used here was already used for another identifier. | N |

`198` | Using the operation `ord` or a lag/lead operation with a set that is not ordered. | O |

`256` | Something is wrong with the model specification. This is often a consequential error of another error. Look for other error messages immediately after the solve statement. | I, J |

`257` | The solver is not checked. This may be a consequential error of any GAMS error. | |

`340` | Probably the quotes in a set element reference are missing. | L |

`408` | Surplus closing parentheses, square brackets or braces. | H |

## Error A: Misplaced Semicolons

Maybe the most common error for new users is related to semicolons. Consider the following example adapted from the well-known transportation model [TRNSPORT]:

```
Sets i "canning plants" / Seattle, San-Diego / ;
j "markets" / New-York, Chicago, Topeka / ;
```

The resulting compilation output will contain the following lines:

20 Sets i canning plants / Seattle, San-Diego / ; 21 j markets / New-York, Chicago, Topeka / ; **** $140 $36 ... Error Messages 36 '=' or '..' or ':=' or '$=' operator expected rest of statement ignored 140 Unknown symbol

What went wrong? GAMS statements like the set statement in our example have to terminate with a semicolon, unless the next line of code begins with a reserved word. Now, set statements may extend over several lines and define several sets. In our example, the set statement extends over two lines and two sets are declared. However, there is a semicolon at the end of the first line, therefore GAMS assumes that the set statement ends there. The symbol `j`

at the beginning of the next line has not been declared yet and it is not a GAMS keyword, thus it is marked as `Unknown`

`symbol`

. Note that error `36`

is a consequential error that will disappear as soon as the first error has been resolved.

How do we fix this? There are two ways: either we could drop the semicolon at the end of the first line and thus indicate that the set statement continues to the second line or we could insert the keyword `Set`

at the start of the second line and thus introduce a new set statement. These two alternatives are illustrated below:

```
Sets i "canning plants" / Seattle, San-Diego /
j "markets" / New-York, Chicago, Topeka / ;
```

or

```
Sets i "canning plants" / Seattle, San-Diego / ;
Set j "markets" / New-York, Chicago, Topeka / ;
```

- Note
- In general, GAMS statements have to be terminated with a semicolon. The semicolon may be omitted if the next line starts with a GAMS keyword.
- Even if it is not required, it is good practice to always end a statement with a semicolon.

## Error B: Missing Semicolons

Consider the following example adapted from the well-known transportation model [TRNSPORT]:

```
Equations
cost "define objective function"
supply(i) "observe supply limit at plant i"
demand(j) "satisfy demand at market j"
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
```

The resulting compilation output will contain the following lines:

52 Equations 53 cost define objective function 54 supply(i) observe supply limit at plant i 55 demand(j) satisfy demand at market j 56 57 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; **** $97 $195,96,195,96 $195,96 ... Error Messages 96 Blank needed between identifier and text (-or- illegal character in identifier) (-or- check for missing ';' on previous line) 97 Explanatory text can not start with '$', '=', or '..' (-or- check for missing ';' on previous line)

What went wrong? GAMS statements like the equation declaration in our example have to terminate with a semicolon, unless the next line of code begins with a GAMS keyword. In our example, we omitted the semicolon at the end of the equation declaration statement and started a new statement after a blank line.

How do we fix this? We simply add a semicolon after the last explanatory text at the end of the equation declaration statement.

- Note
- A missing semicolon is often associated with error
`96`

or`97`

.

## Error C: Spelling Mistakes

This error occurs if sets, set elements, parameters, etc. are referenced with a different name than the name they were declared with. Note that differences in capitalization are not considered spelling mistakes since GAMS is case insensitive.

Consider the following example adapted from the well-known transportation model [TRNSPORT]:

```
Sets i "canning plants" / Seattle, San-Diego /
j "markets" / New-York, Chicago, Topeka / ;
Parameters a(i) "capacity of plant i in cases"
/ Seatle 350
san-diego 600 / ;
...
Equations
cost "define objective function"
supply(i) "observe supply limit at plant i"
demand(j) "satisfy demand at market j" ;
cst .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
```

The resulting compilation output will contain the following lines:

20 Sets i canning plants / Seattle, San-Diego / 21 j markets / New-York, Chicago, Topeka / ; 22 23 Parameters a(i) capacity of plant i in cases 24 / Seatle 350 **** $170 25 san-diego 600 / ; ... 49 Equations 50 cost define objective function 51 supply(i) observe supply limit at plant i 52 demand(j) satisfy demand at market j ; 53 54 cst .. z =e= sum((i,j), c(i,j)*x(i,j)) ; **** $140 ... Error Messages 140 Unknown symbol ... 170 Domain violation for element

What went wrong? Note that in line 24 the set element `Seattle`

was referenced as `Seatle`

. GAMS does not recognize this symbol as an element of the set `i`

and thus marks this with error `170`

: `Domain`

`violation`

. GAMS catches this error since it automatically performs domain checking. The typo in line 54, where the equation `cost`

is referenced as `cst`

, is marked with error `140`

(`Unknown`

`symbol`

), since `cst`

was *not* declared before.

- Note
- Set name misspellings are associated with error
`120`

, set element misspellings with`170`

and other misspellings with`140`

.

Fixing errors like these is as easy as fixing typos.

## Error D: Missing Set Elements

Sometimes users forget to include an element in a set statement, but reference it later. Consider the following simple example:

```
Set c "crops" / barley, wheat, soy /;
Parameter d(c) "demand in metric tons" / rice 3, barley 1, wheat 4, soy 2 /;
```

The resulting compilation output will contain the following lines:

1 Set c "crops" / barley, wheat, soy /; 2 Parameter d(c) "demand in metric tons" / rice 3, barley 1, wheat 4, soy 2 /; **** $170 ... Error Messages 170 Domain violation for element

What went wrong? Note that the symbol `rice`

was not defined as an element of the set `c`

, thus GAMS does not recognize it and marks it with error `170`

: `Domain`

`violation`

. GAMS catches this error since it automatically performs domain checking.

- Note
- If symbols are not defined as set elements, but are referenced as if they belong to the set later, error
`170`

will occur.

This is easy to fix: we just add the missing element(s) to the elements of the respective set.

## Error E: Problems with Indices

Recall that variables, sets, parameters and equation may be defined over one or more indices. If the identifiers are referenced later in the program, the indices must appear exactly in the order that was specified in the respective definition statement. Consider the following example adapted from the well-known transportation model [TRNSPORT]:

```
Sets i "canning plants" / seattle, san-diego /
j "markets" / new-york, chicago, topeka / ;
Table d(i,j) "distance in thousands of miles"
new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4 ;
Scalar f "freight in dollars per case per thousand miles" /90/ ;
Parameter c(i,j) "transport cost in thousands of dollars per case" ;
c(i,j,j) = f * d(j,i) / 1000 ;
```

The resulting compilation output will contain the following lines:

40 Parameter c(i,j) transport cost in thousands of dollars per case ; 41 c(i,j,j) = f * d(j,i) / 1000 ; **** $148 $171,171 ... Error Messages 148 Dimension different - The symbol is referenced with more/less indices as declared 171 Domain violation for set

What went wrong? Note that the parameter `c`

was declared over two indices, but in the assignment statement in line 41 it is referenced with three indices. Such a mistake is marked with error `148`

. Note further, that the indices of `d`

are referenced in the wrong order, which is marked with error `171`

.

- Note
- If an identifier is referenced with more or less indices as declared, then the error
`148`

will be triggered. If the indices are in the wrong order, the error`171`

will be triggered.

This is easy to fix: we just check the declaration or definition statement(s) and adjust the reference.

Observe that the domain error `171`

is also triggered if an identifier is referenced with index say `i`

, but was defined over say `j`

. However, there will be no domain error if `i`

is a subset of `j`

or `i`

and `j`

reference the same set since they are aliases.

## Error F: Summing over Sets that are Already Indexed

Consider the following equation definition that is adapted from the well-known transportation model [TRNSPORT]:

```
supply(i) .. sum((i,j), x(i,j)) =l= a(i) ;
```

The resulting compilation output will contain the following lines:

59 supply(i) .. sum((i,j), x(i,j)) =l= a(i) ; **** $125 ... Error Messages 125 Set is under control already

What went wrong? Note that the equation is indexed over the set `i`

, therefore the indexed operation `sum`

in the body of the equation may not be controlled by the index `i`

again.

- Note
- Summing over sets that are already indexed will trigger error
`125`

.

How do we fix this? We need to carefully check the indexed operation and drop the surplus index. In other cases the controlling index may have to be dropped from the equation name. Note that an error like this is often indicative of a lack of clarity in thinking.

## Error G: Uncontrolled Sets

Consider the following equation definition that is adapted from the well-known transportation model [TRNSPORT]:

```
demand .. sum(i, x(i,j)) =g= b(j) ;
```

The resulting compilation output will contain the following lines:

61 demand .. sum(i, x(i,j)) =g= b(j) ; **** $149 $149 ... Error Messages 149 Uncontrolled set entered as constant

What went wrong? Note that the variable `x`

is indexed over the sets `i`

and `j`

, but, while `i`

is the index of the indexed operation `sum`

, `j`

is "free": it does neither appear as index of the equation nor as controlling index in `sum`

. Therefore it was entered as if it were a constant. Note further, that `j`

is also used as an index on the right-hand side of the equation without being controlled.

- Note
- Error
`149`

marks instances when an index is not controlled in the context of an equation or an indexed operation like`sum`

or`prod`

.

How do we fix this? We have to think what we actually want to model. In this case we need to enter `j`

as a controlling index for the equation. But it would also be possible to add it as a controlling index for `sum`

(but not both!). In the latter case there would still be the error on the right-hand side which needed to be taken care of with another indexed operation, e.g., `sum`

again. Both approaches would remove the compilation error, but one has to think about what actually should be modeled to decide which is the right fix here.

## Error H: Mismatched Parentheses

Consider the following two equations adapted from the model [CHENERY]:

```
mb(i).. x(i) =g= y(i) + sum(j, aio(i,j)*x(j)) + ( e(i) - m(i) ))$t(i) ;
...
dvv(i)$(sig(i) <> 0).. vv(i) =e= (pi*(1-del(i))/del(i))**(-rho(i)/(1+rho(i)) ;
```

The resulting compilation output will contain the following lines:

137 mb(i).. x(i) =g= y(i) + sum(j, aio(i,j)*x(j)) + ( e(i) - m(i) ))$t(i) ; **** $408,409 ... 155 dvv(i)$(sig(i) <> 0).. vv(i) =e= (pi*(1-del(i))/del(i))**(-rho(i)/(1+rho(i)) ; **** $8 ... Error Messages 8 ')' expected ... 408 Too many ),] or } 409 Unrecognizable item - skip to find a new statement looking for a ';' or a key word to get started again

What went wrong? Note that in the first equation we have one surplus closing parenthesis, this is marked with error `408`

. The error marked with `409`

is a consequential error, it will disappear once the first error has been fixed. In the second equation, one closing parenthesis is missing resulting in error `8`

.

- Attention
- Opening and closing parentheses
`( )`

, square brackets`[ ]`

and braces (curly brackets)`{ }`

must match.

- Note
- Surplus closing parentheses, bracketes and braces are marked with error
`408`

and missing closing parenthesis, brackets and braces are marked with error`8`

.*Missing**opening*parentheses, brackets and braces may result in GAMS marking*surplus**closing*parentheses, brackets and braces;*surplus**opening*parentheses, brackets and braces may result in GAMS marking*missing**closing*parentheses, brackets and braces.

While fixing errors like these entails carefully counting opening and closing parentheses, there are strategies that help to prevent mismatching parentheses errors. Many text editors (like GAMS Studio) offer a feature that identifies matching parentheses and will issue a warning if there is a mismatch. We recommend to use this feature. Further, we recommend to also use the alternatives to parentheses: square brackets and braces. They are especially useful if there are several opening parentheses since it is easier to determine by inspection if each has a matching closing symbol.

## Error I: Mistakes Relating to Equations

Recall that each declared equation must be defined if it is to be used in a model statement. If the equation definition is missing, GAMS will mark an error beneath the solve statement that refers to a model which references the respective undefined equation. Consider the following example adapted from the well-known transportation model [TRNSPORT]:

```
Equations
cost "define objective function"
supply(i) "observe supply limit at plant i"
demand(j) "satisfy demand at market j" ;
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
supply(i) .. sum(j, x(i,j)) =l= a(i) ;
Model transport /all/ ;
solve transport using lp minimizing z ;
```

The resulting compilation output will contain the following lines:

60 Model transport /all/ ; 61 solve transport using lp minimizing z ; **** $71,256 **** The following LP errors were detected in model transport: **** 71 demand is an undefined equation ... Error Messages 71 The symbol shown has been declared as an equation, but no Symbolic equation (..) was found. hint - look for commas in the Documentation text for the equations. use quotes around the Text or eliminate the commas. 256 Error(s) in analyzing solve statement. More detail appears Below the solve statement above

What went wrong? Note that the equation `demand`

was declared and included in the model `transport`

, but it was not defined. GAMS detects that the equation definition is missing when it compiles the solve statement that relates to the model `transport`

. Therefore the error `71`

appears only there. The error `256`

is a consequential error, it will disappear once the missing equation definition has been added (*before* the solve statement).

- Note
- Error
`71`

marks a missing equation definition. The message associated with this error is a nice example of an error message that is very descriptive and offers advice on how to fix the error.

Apart from forgetting to define a declared equation and forgetting to terminate the equation definition statement with a semicolon (see above), two other mistakes relating to equations are frequent: omitting the syntax element `..`

after the name of the equation and not properly defining the equation type in the equation definition statement. The following simple example adapted from the portfolio analysis model [ALAN] illustrates these mistakes:

```
fsum sum(i, x(i)) =e= 1.0;
dmean.. sum(i, mean(i)*x(i)) = target;
```

The resulting compilation output will contain the following lines:

45 fsum sum(i, x(i)) =e= 1.0; **** $36 46 dmean.. sum(i, mean(i)*x(i)) = target; **** $37 ... Error Messages 36 '=' or '..' or ':=' or '$=' operator expected rest of statement ignored 37 '=l=' or '=e=' or '=g=' operator expected

What went wrong? Note that in the first equation the two dots `..`

are missing, which is marked with error `36`

, and in the second equation the equation type is not properly specified, which leads to error `37`

.

## Error J: Issues with Nonlinear Expressions

The compilation error messages `51`

to `60`

refer to issues with nonlinear expressions involving variables in equations. For example, nonlinear expressions in an LP model will cause errors of this sort. So will discontinuous functions with endogenous arguments in an NLP model. For information on endogenous arguments in functions, see section Functions in Equation Definitions. For an overview of GAMS model types, see section Classification of Models.

Consider the following simple artificial example:

```
Variables x, y, z ;
Equations eq1, eq2 ;
eq1.. x**2 - y =e= z ;
eq2.. min(x,y) =l= 20 ;
Model silly / all / ;
solve silly using lp maximizing z ;
```

The resulting compilation output will contain the following lines:

7 Model silly / all / ; 8 solve silly using lp maximizing z ; **** $54,51,256 **** The following LP errors were detected in model silly: **** 54 equation eq1.. VAR operands for ** **** 51 equation eq2.. the function MIN is called with non-constant arguments Error Messages 51 Endogenous function argument(s) not allowed in linear models 54 Endogenous operands for ** not allowed in linear models 256 Error(s) in analyzing solve statement. More detail appears Below the solve statement above

Note that error `54`

marks the nonlinear expression \(x^2\) in a linear model and error `51`

refers to the discontinuous function `min`

that may be used with variables only in models of the type DNLP. The error `256`

is a consequence of the two previous errors.

## Error K: Using Undefined Data

Referencing data items that were not declared with a scalar, parameter or table statement will cause error `140`

: GAMS will indicate that the respective symbol is unknown. More often data items are declared, but not defined, i.e. they are not initialized with values.

Consider the following example adapted from the well-known transportation model [TRNSPORT]. Assume that the scalar `f`

is declared, but has no numerical value. The resulting compilation output will contain the following lines:

40 Scalar f freight in dollars per case per thousand miles ; 41 42 Parameter c(i,j) transport cost in thousands of dollars per case ; 43 44 c(i,j) = f * d(i,j) / 1000 ; **** $141 ... 61 Model transport /all/ ; 62 solve transport using lp minimizing z ; **** $257 63 64 display x.l, x.m ; **** $141 ... Error Messages 141 Symbol declared but no values have been assigned. Check for missing data definition, assignment, data loading or implicit assignment via a solve statement. A wild shot: You may have spurious commas in the explanatory text of a declaration. Check symbol reference list. 257 Solve statement not checked because of previous errors

What went wrong? Note that the scalar `f`

was declared, but there was no value assigned to it. Thus, when it is referenced in the calculation in line 44, the "empty" scalar causes error `141`

. Error `257`

is a consequential error and leads to the second error `141`

. This error occurs in the context of variable attributes in the display statement. Recall that variable attributes are data associated with variables. As the solve statement could not be checked, the level and marginal values of the variable `x`

are not defined and hence error `141`

follows.

- Note
- Error
`141`

marks places where data items, that have not been defined, are referenced in computations in the context of assignment statements. It also marks places where undefined variable (or equation) attributes are referenced.

In addition, undefined data items may be referenced in the context of equation definitions. Suppose we declare the parameter `c`

in model [TRNSPORT], but forget the corresponding assignment statement. Then the compilation output will contain the following lines:

57 cost .. z =e= sum((i,j), c(i,j)* x(i,j)) ; ... 62 solve transport using lp minimizing z ; **** $66,256 **** The following LP errors were detected in model transport: **** 66 equation cost.. symbol "c" has no values assigned ... Error Messages 66 The symbol shown has not been defined or assigned A wild shot: You may have spurious commas in the explanatory text of a declaration. Check symbol reference list. 256 Error(s) in analyzing solve statement. More detail appears Below the solve statement above

Note that the missing data in the body of the equation `cost`

is marked with error `66`

and the following error is a consequential error which will disappear once `66`

has been fixed.

- Note
- Referencing undefined data items in the body of an equation causes error
`66`

.

## Error L: Referencing Set Elements Without Quotes

Recall that if set elements are referenced, they need to appear in single or double quotes. Omitting the quotes may cause different errors depending on the context. The following example is adapted from the well-known transportation model [TRNSPORT]. Suppose we start by defining the two sets and the two parameters and then add the following statements:

```
Scalar s;
s = a(seattle);
```

The resulting compilation output will contain the following lines:

37 Scalar s; 38 s = a(seattle); **** $120,340,149,171 ... Error Messages 120 Unknown identifier entered as set 149 Uncontrolled set entered as constant 171 Domain violation for set 340 A label/element with the same name exist. You may have forgotten to quote a label/element reference. For example, set i / a,b,c /; parameter x(i); x('a') = 10;

What went wrong? On the right-hand side of the assignment statement we have a reference with missing quotes. Note that this creates four (!) errors:

`120`

- GAMS expects a controlling set and`Seattle`

is not recognized and therefore considered an unknown identifier.`340`

- Then GAMS realizes that actually there is a label called`Seattle`

in the program and helpfully offers a hint:`You may have forgotten to quote a label/element reference.`

`149`

- See section Error G: Uncontrolled Sets above.`171`

- See section Error E: Problems with Indices above.

This is a nice example for one mistake triggering several errors that may look daunting. However, fixing them is as easy as adding single or double quotes.

## Error M: Missing Declaration Statements

Recall that sets, parameters, variables and equations have to be declared before they may be used in definition or assignment statements. Suppose the equation `demand`

in the well-known transportation model [TRNSPORT] was defined but not declared. Then the compilation output would contain the following lines:

59 demand(j) .. sum(i, x(i,j)) =g= b(j) ; **** $140 ... Error Messages 140 Unknown symbol

Note that as `demand`

was not declared, GAMS does not recognize it and therefore marks it with error `140`

: `Unknown symbol`

.

- Note
- If error
`140`

is reported, the respective declaration statement is probably missing. However, the underlying cause may also be a simple typo.

## Error N: Using the Same Name for Different Identifiers

Recall that each GAMS identifier must have a unique name. If the same name is used more than once, an error will be triggered. Consider the following modification of the transportation model [TRNSPORT]:

```
Parameters capacity(i) "capacity of plant i in cases"
/ Seattle 350, San-Diego 600 /
demand(j) "demand at market j in cases"
/ New-York 325, Chicago 300, Topeka 275 /;
...
Equations
cost "define objective function"
supply(i) "observe supply limit at plant i"
demand(j) "satisfy demand at market j" ;
```

The resulting compilation output will contain the following lines:

47 Equations 48 cost define objective function 49 supply(i) observe supply limit at plant i 50 demand(j) satisfy demand at market j ; **** $195 ... Error Messages 195 Symbol redefined with a different type

What went wrong? Note that `demand`

was first declared as a parameter and later as an equation. GAMS will mark this repeated use of the same name with error `195`

.

## Error O: Using ORD with an Unordered Set

Recall that the operation ord is only defined for ordered sets. If `ord`

is used with an unordered set, error `198`

will be triggered.

Consider the following example:

```
Set a "a couple of the elements" / r2, r3 /;
Set b "more elements" / r1*r4 /;
Scalar c "counter" / 0 /;
loop( b $ (ord(b) > 3),
c = c + 1 );
display c;
```

The resulting compilation output will contain the following lines:

5 loop( b $ (ord(b) > 3), **** $198 6 c = c + 1 ); ... Error Messages 198 Set used in 'ord' or lag is not ordered. Hint: Some of the elements of the set were used before this was initialized and the order was different from the order used in this set. Try to initialize the set earlier. $offOrder allows lag operations on dynamic sets, reset with $onOrder

What went wrong? Two elements of the set `b`

featured already in set `a`

that was defind before set `b`

. Therefore the order of the elements in set `b`

is as follows:

```
r2 r3 r1 r4
```

Obviously, this set is not orderd and hence GAMS marks error `198`

when the operator `ord`

is applied to it.

How do we fix this? In this case it is easy: we just define the set `b`

before set `a`

and `b`

will be an ordered set.

Consider one last example:

```
Set a "all elements" / r1*r10 /;
Set b "elements in different order" / r3, r1, r4, r7 /;
Scalar c "counter" / 0 /;
loop( b $ (ord(b) > 3),
c = c +1 );
display c;
```

The resulting compilation output will contain the following lines:

5 loop( b $ (ord(b) > 3), **** $198 6 c = c +1 );

What went wrong? Note that even though all elements in set `b`

are also elements of set `a`

, they are not specified in the same order. Therefore the set `b`

is unordered. For more details, see section Ordered and Unordered Sets.