Execute, load excel file and read parameters´value

Problems with syntax of GAMS
Post Reply
Posts: 9
Joined: 11 months ago

Execute, load excel file and read parameters´value

Post by ZNSen » 10 months ago

Hi dear all,

I want to read an excel sheet in GAMS. the file contains series of 500 values per year for each variable a,b and c. it is a parameter that I define as Stk(yr,i,se). The values are saved in an excel sheet with 3 dimensions Rdim=2 Cdim=1 like the following example
1 2 3 ...500
a y1
a y2
a y10
b y1
b y2
b y10

So I proceed this way (see code below) but it couldn´t work out . the erroe messages are:
140 Unknown symbol (related to 'a' in the following declaration ----->Randomdata('a',Yr,Se) = Rdata('Maize',Yrn0,Se) ;
149 Uncontrolled set entered as constant (related to 'Se' in the following declaration ----->Randomdata('a',Yr,Se) = Rdata('Maize',Yrn0,Se)).

But before that they was an error related to the lign (execute 'gdxxrw.exe......), I think that it was not well stated.

Please provide some hints. Thanks for your consideration

Code: Select all

Se series of stochastic yield term           /1*500/
   i products       / a,b,c /
   Yr  year        / 2014*2025/

   t0(Yr)           Year 0
   tl(Yr)           Last year

   Yrn0(Yr) time path /2014*2025/

   ti(Yrn0)        first year for considered time frame
   tf(Yrn0)        final year for considered time frame

   crop  for data calculations       /a,b,c/


* read data from Excel
execute 'gdxxrw.exe i="stochastic yields.xlsx" o=Randomdata.gdx par=Rdata rng=Sample!A1 Rdim=2 Cdim=1 MaxDupeErrors = <500> ';

execute_load 'Randomdata.gdx', Rdata;

Display  Rdata   ;

* stochastic yield data
Randomdata('a',Yr,Se) = Rdata('Maize',Yrn0,Se) ;
Randomdata('b',Yr,Se) = Rdata('Rice',Yrn0,Se) ;
Randomdata('c',Yr,Se) = Rdata('Sorghum',Yrn0,Se) ;

*Assign values
 stk('Yr0',i,Se)= 0       ;
STK(Yr,i,Se)=  Rdata(crop,Yrn0,Se)        ;]

User avatar
Site Admin
Site Admin
Posts: 5
Joined: 1 year ago

Re: Execute, load excel file and read parameters´value

Post by gamsadmin » 10 months ago

Add Trace = 3 at the end of your gdxxrw command and you will see if there are errors when importing the data.
I only see that you define Stk(yr,i,se) but in the table the order seems to be i,yr,se (or se,yr,i).

Post Reply