Page 1 of 1

Created a loop including CSVs

Posted: Fri Dec 07, 2018 9:00 am
by richard
Hi all,

Is there any way to refer to the CSV files in a loop?
All my files have systematic names: file1.csv, file2.csv etc. How do I create a loop including all the files?

I am looking for something like this:

set j /1*10/
loop(j,
$include "filej.csv")
How do I go about it?

Re: Created a loop including CSVs

Posted: Fri Dec 14, 2018 10:06 am
by Renger
Hi Richard

Just starting to learn how to use embededded code in Gams. Here a solution with python:

Code: Select all

$onEmbeddedCode Python:
  f = open('myinclude.inc', 'w')
  for i in range(10):
     f.write('$include'+'" file' + str(i)+'.csv"\n')
  f.close()
$offEmbeddedCode

$include myinclude.inc
Hope this helps
Cheers
Renger

Re: Created a loop including CSVs

Posted: Fri Dec 14, 2018 11:05 am
by richard
Hi @Renger , Thanks a lot ! It was very helpful.