Export result (CSV) in a loop

Problems with syntax of GAMS
Post Reply
pmgcs74@gmail.com
User
User
Posts: 18
Joined: 3 years ago

Export result (CSV) in a loop

Post by pmgcs74@gmail.com »

Hi all,

I'm currently have a model that is running on a loop to test several configurations on different scalar/parameters.
Different set of configurations = different results that I want to store and analyse later

On a single run, I can export a csv file with detail results from GAMS.
When I try to run it on a loop i get " 349 Declaration not allowed inside a LOOP or IF statement" message

is there an alternative to this ?

Thanks
Paulo
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Export result (CSV) in a loop

Post by bussieck »

It would help if you post the related source lines that create this error. I assume you try to declare a put file inside the loop and somehow use the loop set index as a file name. That's not possible, but with the put_utility 'ren' (https://www.gams.com/37/docs/UG_Put.html#UG_Put_PutUtil) you can rename the put stream inside the loop:

Code: Select all

file fcsv / x.csv /; put fcsv;
set i /1*3/;
loop(i,
  put_utility 'ren' / i.tl:0 '.csv';
  put fcsv 'a,b,c', / i.val,(i.val+1),(i.val+2);
);  
Creates three CSV files 1.csv, 2.csv, and 3.csv.

-Michael
Post Reply