Loading data from Excel Sheet into GAMS

Problems with syntax of GAMS
Post Reply
omarrossan
User
User
Posts: 9
Joined: 10 months ago

Loading data from Excel Sheet into GAMS

Post by omarrossan »

Hello Everyone,

I want to load data from excel sheet into GAMS, each excel sheet has one column and 8760 rows (where each row has a values), and I am using the below code,

Parameter PV_Available(k);
$call gdxxrw "C:\Users\omarr\OneDrive\Desktop\GAMS\Model Development\Fourth Draft (First Run)\Data\PV_Available.xlsx" par=PV_Available rng=Sheet1!A1:A8760 rdim=1 output="PV_Available.gdx"
$gdxin PV_Available.gdx
$load PV_Available
$gdxin

Parameter Wind_Available(k);
$call gdxxrw "C:\Users\omarr\OneDrive\Desktop\GAMS\Model Development\Fourth Draft (First Run)\Data\Wind_Available.xlsx" par=Wind_Available rng=Sheet1!A1:A8760 rdim=1 output="Wind_Available.gdx"
$gdxin Wind_Available.gdx
$load Wind_Available
$gdxin

The code is running without errors, but the created gdx files do not have the data avaialble in the excel sheets,

Could someone please help me identifying where is the error?
Kind regards,
Omar
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Loading data from Excel Sheet into GAMS

Post by bussieck »

Sure, if you provide the Excel files to see what's going on.

-Michael
omarrossan
User
User
Posts: 9
Joined: 10 months ago

Re: Loading data from Excel Sheet into GAMS

Post by omarrossan »

Hi Michael,

Thank you for your reply!

I have attached the excel sheets and the created gdx files,

I hope you will be able to access them,

kind regards,
Omar
Attachments
Wind_Available.gdx
(86.31 KiB) Downloaded 94 times
PV_Available.gdx
(48.52 KiB) Downloaded 86 times
Wind_Available.xlsx
(136.18 KiB) Downloaded 88 times
PV_Available.xlsx
(108.11 KiB) Downloaded 106 times
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: Loading data from Excel Sheet into GAMS

Post by bussieck »

Please read the documentation of gdxxrw at https://www.gams.com/latest/docs/T_GDXXRW.html. All parameters are read with the index k and the value of the parameter in the neighboring cell. Your sheets don't mention the index (k) at all. You did not provide the elements of set k, but here I am assuming the set k consists of k1,k2,k3,...,k8760 then your Excel data should look as follows:
Screenshot 2023-06-22 131125.png
Screenshot 2023-06-22 131125.png (7.9 KiB) Viewed 5459 times
and you need to adjust your rng parameter to rng=Sheet1:A1:B8760. Then the GDX file will have the expected data.

-Michael
omarrossan
User
User
Posts: 9
Joined: 10 months ago

Re: Loading data from Excel Sheet into GAMS

Post by omarrossan »

Thank you! It works and I have used the documentation to learn how to show the zero values by disabling the squeeze option.
kind regards,
Omar
Post Reply