Page 1 of 1

Cannot Import Data from Excel

Posted: Tue Nov 13, 2018 11:44 pm
by vigoleo
Hello everyone,

I am a very beginner of GAMS. I have just completed my first model in gams, but I was not able to test it on the real dataset because I was not able to import data.
So this is the code I'm working with:

Code: Select all

Set pp    "New production" / pp1,        pp2,        pp3,        pp4,        pp5,        pp6,        pp7,        pp8,        pp9,        pp10,        pp11,        pp12,        pp13,        pp14,        pp15,        pp16,        pp17,        pp18,        pp19,        pp20,        pp21,        pp22,        pp23,        pp24,        pp26,        pp25,        pp27,        pp28,        pp29,        pp30,        pp31,        pp32,        pp33,        pp34,        pp35,        pp36,        pp37,        pp38,        pp39,        pp40,        pp41,        pp42,        pp43,        pp44,        pp45,        pp46,        pp47,        pp48,        pp49,        pp50,        pp51,        pp52,        pp53,        pp54,        pp55,        pp56,        pp57,        pp58,        pp59,        pp60,        pp61,        pp62,        pp63,        pp64,        pp65,        pp66,        pp67,        pp69,        pp68,        pp70,        pp71,        pp72,        pp73,        pp74,        pp75,        pp76,        pp77,        pp78,        pp79,        pp80,        pp81,        pp82,        pp83/;

$call gdxxrw.exe DATA.xlsx par=t rng=Sheet1!D2:D84
Parameter t(pp);
$gdxin DATA.gdx
$load t
$gdxin

display t;
My first question would be: Is there any way to import the "pp" as a set from the range F1:F84 instead of doing it manually?
Second question: In the code I would like to store the times related to domain's elements. Why the program returns me a dimension problem?
I'm attaching the excel file i'm working with.

Thank you for your help.

All the best, Leonardo

Re: Cannot Import Data from Excel

Posted: Wed Nov 14, 2018 7:56 am
by Renger
Hi

In your excel sheet, your data is organized as follows:

Code: Select all

P1	P2	P3	TIMES [H]	QTY	DOMINIO
0	1	0	1.983333333	210	pp1
0	1	0	1.983333333	182	pp2
1	0	0	1.983333333	628	pp3
1	0	0	1.983333333	838	pp4
Gams expects the indices in the first columns and/or rows, so you have to move DOMINIO to the first column (I added "trace = 3". This will shows the errors in the command window):
Furthermore, to read the data, you should set the range according to your excel table and tell Gams the dimensions:

Code: Select all

$call gdxxrw.exe DATA.xlsx par=t rng=Sheet1!A1:F84 Rdim=1 Cdim=1 trace=3
Also, the parameter t is a two-dimensional parameter : t(pp,*).

To read the set t directly, you can change the code as follows:

Code: Select all

$call gdxxrw.exe DATA.xlsx par=t rng=Sheet1!A1:F84 Rdim=1 Cdim=1 set=pp rng=Sheet1!A2:A84 Rdim=1 trace=3
I hope this helps. I strongly suggests to have a closer look at the examples in the gdxxrw documentation.
Cheers
Renger

Re: Cannot Import Data from Excel

Posted: Wed Nov 14, 2018 8:18 am
by vigoleo
Renger wrote: 5 years ago Hi

In your excel sheet, your data is organized as follows:

Code: Select all

P1	P2	P3	TIMES [H]	QTY	DOMINIO
0	1	0	1.983333333	210	pp1
0	1	0	1.983333333	182	pp2
1	0	0	1.983333333	628	pp3
1	0	0	1.983333333	838	pp4
Gams expects the indices in the first columns and/or rows, so you have to move DOMINIO to the first column (I added "trace = 3". This will shows the errors in the command window):
Furthermore, to read the data, you should set the range according to your excel table and tell Gams the dimensions:

Code: Select all

$call gdxxrw.exe DATA.xlsx par=t rng=Sheet1!A1:F84 Rdim=1 Cdim=1 trace=3
Also, the parameter t is a two-dimensional parameter : t(pp,*).

To read the set t directly, you can change the code as follows:

Code: Select all

$call gdxxrw.exe DATA.xlsx par=t rng=Sheet1!A1:F84 Rdim=1 Cdim=1 set=pp rng=Sheet1!A2:A84 Rdim=1 trace=3
I hope this helps. I strongly suggests to have a closer look at the examples in the gdxxrw documentation.
Cheers
Renger
Thank you Renger,

I only have been aware of the GDXXRW guidelines a few hours ago. I'm going through that right now.

Thank you for yuor help.

Leonardo