Can I change the decimal symbol from a dot to a comma?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 3 years ago

Can I change the decimal symbol from a dot to a comma?

Post by aileen »

Can I change the decimal symbol from a dot to a comma?
aileen
User
User
Posts: 136
Joined: 3 years ago

Re: Can I change the decimal symbol from a dot to a comma?

Post by aileen »

The short answer is no, this is not possible within GAMS. However it only becomes an issue when importing data in ASCII format (i.e. csv-files). Here is a simple example (input.csv) generated with the German regional settings of Windows:

Code: Select all

dummy;new-york;chicago;topeka
seattle;2,5;1,7;1,8
san-diego;2,5;1,8;1,4
To change the comma into a dot and the semicolon into a comma we just use one of the POSIX tools, which are part of any GAMS system and write a few lines of GAMS code:

Code: Select all

* translate , to . using tr
$call "tr , . <input.csv >temp.csv"
* translate ; to , using tr
$call "tr ; , <temp.csv >output.csv"
table data(*,*)
$ondelim
$include output.csv
$offdelim
;
display data;
or

Code: Select all

* translate , to . and ; to , using sed
$onecho > sedscript
s/,/./g
s/;/,/g
$offecho
$call sed -f sedscript input.csv > output.csv
table data(*,*)
$ondelim
$include output.csv
$offdelim
;
display data;
and get

Code: Select all

----     14 PARAMETER data  

             new-york     chicago      topeka

seattle         2.500       1.700       1.800
san-diego       2.500       1.800       1.400
Locked