Bad dimension error when using gdxxrw

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

Bad dimension error when using gdxxrw

Post by Sarah_Chamberland » 1 week ago

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 5 times

User avatar
Renger
Posts: 266
Joined: 2 years ago

Re: Bad dimension error when using gdxxrw

Post by Renger » 1 week ago

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

Sarah_Chamberland
User
User
Posts: 5
Joined: 1 month ago

Re: Bad dimension error when using gdxxrw

Post by Sarah_Chamberland » 6 days ago

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

Post Reply