Loop over strings

Problems with syntax of GAMS
Post Reply
GAMSisGREAT
User
User
Posts: 11
Joined: 6 years ago

Loop over strings

Post 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.
User avatar
Gideon Kruseman
User
User
Posts: 24
Joined: 6 years ago

Re: Loop over strings

Post 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;
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-economic data @CGIAR_BigData
GAMSisGREAT
User
User
Posts: 11
Joined: 6 years ago

Re: Loop over strings

Post by GAMSisGREAT »

Thank you very much for this quick help!
Post Reply