Bad dimension error when using gdxxrw

Problems with syntax of GAMS
Post Reply
Sarah_Chamberland
User
User
Posts: 5
Joined: 5 years ago

Bad dimension error when using gdxxrw

Post by Sarah_Chamberland »

Hi everyone,

I am having a "Symbol: ZIMSAM2 Bad dimension: 1" error when importing a parameter into GAMS from Excel. See the code below:

Code: Select all

PARAMETER ZIMSAM2(AC, ACP)
$call gdxxrw input="C:\Users\zimb_pan.xlsx" output="C:\Users\zimb_pan_sam.gdx" par=ZIMSAM2 rng=Sheet1!A1:AI35 rdim=1 cdim=1;
AC refers to every single variable in the model and ACP is an Alias for AC.
I understand that the error comes from cDim = 1 because when I increase cdim to a value x, the error message changes to Bad dimension:x.
Yet I know that labels are defined at column 1... So I am confused.

I joined the Excel file as an attachment.

Any help is appreciated!

Sarah
Attachments
zimb_pan.xlsx
(11.3 KiB) Downloaded 212 times
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Bad dimension error when using gdxxrw

Post by Renger »

Hi Sarah
It looks like you haven't defined AC yet. If I define the parameter PARAMETER ZIMSAM2(*, *) instead of PARAMETER ZIMSAM2(AC,ACP), the import runs fine.
Did you define/import AC before you want to import ZIMSAM2?
Hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Sarah_Chamberland
User
User
Posts: 5
Joined: 5 years ago

Re: Bad dimension error when using gdxxrw

Post by Sarah_Chamberland »

Hi Renger,
Thank you for this prompt reply. I did define AC previously, as well as ACP as an alias for AC. Furthermore, I can import all my data correctly if I enter it manually in the following way:

Code: Select all

TABLE ZIMSAM2(AC,ACP)   8-SECTOR MICROSAM FOR ZIMBABWE ($Zim mill 1991)

              AAGEX       AAGFO       AAGOT       AMINE       ANAFO       ANAOI

CAGEX                                                       341.998    1135.653
CAGFO                                                       243.014
CAGOT         6.304                 244.130                 827.023     142.909
CMINE                                            91.141      39.080    1268.605
This is a subsection of the data, but it would be too long to enter all of it manually, hence my interest in uploading the data from Excel.

So my question is the following: I can write ZIMSAM2(AC, ACP) in a table and GAMS will recognize the parameter ZIMSAM2, as well as AC and ACP, but I don't understand why GAMS won't do the same if I import the data from Excel?

Thanks again!

Sarah
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: Bad dimension error when using gdxxrw

Post by GFA »

Hi Sarah,

You don't need semicolons after "$"-statements.
Here GAMS gives the error: "ZIMSAM2 Bad dimension: 1;"
Drop the semicolon in "cdim=1;" and it should work fine.

Auke
Post Reply