load data from excel with specific structure

Problems with syntax of GAMS
Post Reply
dasa
User
User
Posts: 13
Joined: 4 years ago

load data from excel with specific structure

Post by dasa »

Dear all,

Instead of writing table g (as you can see in the code) in gams, i wanna load it from excel.

Code: Select all

set m /1*3/;
alias (m,n);

Table g(m,n,*)
            a                b
1.2        0.00375     0.00275
1.3        0.00375     0.0035
2.3        0.001875    0.0015
;
I have written some code. however, it doesn't work. Could someone modify or give me some idea?
Thanks you !!!

Code: Select all

set m /1*3/;
alias (m,n);
parameter g(*,*) ;
$onecho> p.txt
Par=g        rng=DG!C4:E7   rdim=1   cdim=1
$offecho

$call GDXXRW p.xlsx Squeeze=N trace=3 @p.txt
$gdxin p.gdx
$load g
$gdxin
display g;
p.xlsx
(7.92 KiB) Downloaded 211 times
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: load data from excel with specific structure

Post by GFA »

p.xlsx
(8.17 KiB) Downloaded 203 times
Hi dasa,

See code below, should be working with attached XLSX. Made some small changes, but most important is that every dimension needs its own column/row in Excel.

Regards,
GFA

Code: Select all

set m /1*3/;
alias (m,n);
parameter g(*,*,*) ;
$onecho> p.txt
Par=g        rng=S1!B4:E7   rdim=2   cdim=1
$offecho

$call GDXXRW i='p.xlsx' 'o=p.gdx' Squeeze=N trace=3 @p.txt
$gdxin 'p.gdx'
$load g
$gdxin
display g;
dasa
User
User
Posts: 13
Joined: 4 years ago

Re: load data from excel with specific structure

Post by dasa »

GFA wrote: 3 years ago p.xlsx

Hi dasa,

See code below, should be working with attached XLSX. Made some small changes, but most important is that every dimension needs its own column/row in Excel.

Regards,
GFA

Code: Select all

set m /1*3/;
alias (m,n);
parameter g(*,*,*) ;
$onecho> p.txt
Par=g        rng=S1!B4:E7   rdim=2   cdim=1
$offecho

$call GDXXRW i='p.xlsx' 'o=p.gdx' Squeeze=N trace=3 @p.txt
$gdxin 'p.gdx'
$load g
$gdxin
display g;
Dear GFA,

Thanks for your response. it's work great. but how to use this g(*,*,*) after we load it ? i.e. we want to use the value of g(1,2,'a').

Best regards,
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: load data from excel with specific structure

Post by GFA »

Dear dasa,

Try using "" for example:
g("1","2","a")

Also have a look here for more information on GAMS syntax: https://www.gams.com/latest/docs/UG_MAI ... nvironment

Best,
GFA
Post Reply