Page 1 of 1

Loop over strings

Posted: Mon Jan 29, 2018 2:35 pm
by GAMSisGREAT
I would like to undertake some sensitivity analysis and have some datasets with different names which I want to call in a loop and have these related to parameters for display (or other things). For example, the datasets are called dataA.xls, dataB.xls, dataC.xls. The parameters for display would be called e.g. para("A")=a.L, para("B")=a.L, and para("C")=a.L. How do I make sure that GAMS treats my A,B and C as a string? The <i> that I used in the loop is obviously wrong but I'd be happy if someone can let me know about the correct method.

The idea of the loop is to write
set
i /A,B,C/
;
Loop(i,
$include data<i>.inc
then I do something with the data
para("<i>")=a.L
);
display para;

Thanks for any help.

Re: Loop over strings

Posted: Tue Jan 30, 2018 10:30 am
by Gideon Kruseman
Won't work like that.
The $include is a compile time statement and the loop ( ); is an execute time statement.

You can load data before the loop
sets
i "data sets"
j "model set"

;
parameter data(i,j);

parameter modelparameter(j)


include alldata.inc

loop(i,
modelparameter(j)=0;
modelparameter(j)=data(i,j);
*do model stuff
para(i)=a.L;

);

display para;

Re: Loop over strings

Posted: Tue Jan 30, 2018 8:39 pm
by GAMSisGREAT
Thank you very much for this quick help!