Hello
Please consider that " PUT /" is to instruct the cursor to go to the next line. Therefor,e the below code should work for you:
SET n INDEX /1*4/;
PARAMETER A(n)/1 100,2 200,3 300,4 400/;
file FILE1 /“OUTPUT.XLS”/;
put FILE1;
PUT ‘OUTPUT LISTED BELOW’;
PUT /
Loop (n, put A(n); );
One may also try using GDX file. The keyword EXECUTE_UNLOAD can extract the required outputs into a GDX file. Next you can use that GDX file to communicate with other software packages such as MATLAB/EXCEL.
I hope that helps.
Regards
On Wed, Oct 10, 2012 at 1:25 AM, ensie hajinezhad wrote:
Hello
Thanks for your reply. It works, however when I use ‘put’ to create an excel file, the problem is that, i can not write data in two separate cells in one row.
So, how can I shift to a new cell in current row?
From: Tavallali
To: gamsworld@googlegroups.com
Sent: Tuesday, October 9, 2012 5:34 AM
Subject: Re: how can I export data from GAMS to excel in a loop?
Hello
You can use LOOP to iterate on the index of your parameter. Consider the below example. It will write A(n) to a TXT file:
SET n INDEX /1*4/;
PARAMETER A(n)/1 100,2 200,3 300,4 400/;
file FILE1 /“OUTPUT.TXT”/;
put FILE1;
PUT ‘OUTPUT LISTED BELOW’;
PUT /
Loop (n, put A(n); put /);
I hope that helps.
Regards
Ù…Øمد صادق تولّلی
Mohammad Sadegh Tavallali
National University of Singapore
YOu should get the below , printed into “OUTPUT.TXT” in the same directory:
OUTPUT LISTED BELOW
100.00
200.00
300.00
400.00
I hope that helps.
On Mon, Oct 8, 2012 at 8:01 PM, ati wrote:
I am writing a GAMS program. The problem is that, some vectors or tables are needed to be written in one excel file, in a loop. So, I need some routine to open a file and write the data, in the loop.
I try ‘put’, but exporting directly a vector is not possible.
would you please help me.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.