How do I export only rounded numbers from GAMS to Excel?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
User avatar
bussieck
Moderator
Moderator
Posts: 461
Joined: 3 years ago

How do I export only rounded numbers from GAMS to Excel?

Post by bussieck » 3 weeks ago

When unloading data from GAMS to Excel with GDX, is it possible to round numbers or choose the number of decimal to be included in the Excel files?

User avatar
bussieck
Moderator
Moderator
Posts: 461
Joined: 3 years ago

Re: How do I export only rounded numbers from GAMS to Excel?

Post by bussieck » 3 weeks ago

There is no explicit option to round numbers when writing to an Excel file, but you can round within GAMS before writing the data to GDX. You could also use cell formatting in Excel to instruct Excel to show you a certain number of digits. The following will round the parameter abc to two decimal places and export it to Excel:

Code: Select all

$if NOT set fn $set fn 'abc'
set i /i1*i3/;
parameter abc(i);
abc(i)=normal(0,1);
abc(i) = round(abc(i),2);
display abc;
execute_unload '%fn%.gdx', abc;
execute 'gdxxrw %fn%.gdx par=abc rng=a1';

Locked