<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change dot to comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725249#M225228</link>
    <description>&lt;P&gt;Hi:&lt;BR /&gt;Remember that TRANSLATE is a little bit different. The first argument is the variable you want to change and the second argument is the&lt;STRONG&gt;&lt;FONT color="#008000"&gt; new&lt;/FONT&gt; &lt;/STRONG&gt;character to use and the third argument is the &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;character to translate&lt;/STRONG&gt;&lt;/FONT&gt;, like this:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;newvar = translate(oldvar,&lt;FONT color="#008000"&gt;newval&lt;/FONT&gt;,&lt;FONT color="#FF00FF"&gt;OLDval&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;So if you want to CHANGE the . to a , then you'd have:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;newvar=translate(oldvar,&lt;FONT color="#008000"&gt;','&lt;/FONT&gt;,&lt;FONT color="#FF00FF"&gt;'.'&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;with the comma listed as the second argument. However, also note that if your X and Y are numeric, you may receive a NOTE in the log that numeric values have been converted to character. So if you do THIS:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;x=translate(x,',','.');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;then X will effectively be missing after your statement runs, even if you fix the translate function because X has to be character for translate to work and if your X is numeric, the result of the translate function will be assigning a missing value to X. &lt;BR /&gt;&lt;BR /&gt;If all you want to do is display the values with a comma instead of a period, you can do that with the COMMAX format. but if you want to create a new variable, it will have to be character.&lt;BR /&gt;&lt;BR /&gt;Here is an example to try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fakedata;
  infile datalines dlm=',';
  input examp $ numX numY;

  ** create character variables with comma using PUT function;
  charx = put(numX,commax9.5);
  chary = put(numY,commax9.5);

  ** save orig values because they will be missing after translate;
  savenumx = numx;
  savenumy = numy;

  ** now do translate using correct syntax ;
  ** (but numx and numy are numeric so they will be missing after translate);
  numX=translate(numX,',','.');
  numY=translate(numY,',','.');
return;
datalines;
a1,45.12542,12.07830
b2,45.58219,11.98459
;
run;
title;

proc print data=fakedata;
  title 'Display original numbers with commas without using TRANSLATE';
  var examp savenumx savenumy;
  format savenumx savenumy commax9.5;
run;

proc contents data=fakedata;
  title 'check variables type -- new variables are character';
run;

proc print data=fakedata;
  title 'Original numbers show period, character versions show comma';
format savenumx savenumy 9.5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Wed, 10 Mar 2021 19:31:59 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2021-03-10T19:31:59Z</dc:date>
    <item>
      <title>Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725238#M225223</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with some GPS positions including a dot which I want to change to a comma.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example of the data is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;45.12542&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12.07830&lt;/P&gt;
&lt;P&gt;45.58219&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11.98459&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
X=translate(X,'.',',');
Y=translate(Y,'.',',');
run;&lt;/PRE&gt;
&lt;P&gt;But it only returns "missing" values, so all coordinates disappear. Both variables are of course numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All best&lt;/P&gt;
&lt;P&gt;MM&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 18:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725238#M225223</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-03-10T18:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725249#M225228</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;Remember that TRANSLATE is a little bit different. The first argument is the variable you want to change and the second argument is the&lt;STRONG&gt;&lt;FONT color="#008000"&gt; new&lt;/FONT&gt; &lt;/STRONG&gt;character to use and the third argument is the &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;character to translate&lt;/STRONG&gt;&lt;/FONT&gt;, like this:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;newvar = translate(oldvar,&lt;FONT color="#008000"&gt;newval&lt;/FONT&gt;,&lt;FONT color="#FF00FF"&gt;OLDval&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;So if you want to CHANGE the . to a , then you'd have:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;newvar=translate(oldvar,&lt;FONT color="#008000"&gt;','&lt;/FONT&gt;,&lt;FONT color="#FF00FF"&gt;'.'&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;with the comma listed as the second argument. However, also note that if your X and Y are numeric, you may receive a NOTE in the log that numeric values have been converted to character. So if you do THIS:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;x=translate(x,',','.');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;then X will effectively be missing after your statement runs, even if you fix the translate function because X has to be character for translate to work and if your X is numeric, the result of the translate function will be assigning a missing value to X. &lt;BR /&gt;&lt;BR /&gt;If all you want to do is display the values with a comma instead of a period, you can do that with the COMMAX format. but if you want to create a new variable, it will have to be character.&lt;BR /&gt;&lt;BR /&gt;Here is an example to try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fakedata;
  infile datalines dlm=',';
  input examp $ numX numY;

  ** create character variables with comma using PUT function;
  charx = put(numX,commax9.5);
  chary = put(numY,commax9.5);

  ** save orig values because they will be missing after translate;
  savenumx = numx;
  savenumy = numy;

  ** now do translate using correct syntax ;
  ** (but numx and numy are numeric so they will be missing after translate);
  numX=translate(numX,',','.');
  numY=translate(numY,',','.');
return;
datalines;
a1,45.12542,12.07830
b2,45.58219,11.98459
;
run;
title;

proc print data=fakedata;
  title 'Display original numbers with commas without using TRANSLATE';
  var examp savenumx savenumy;
  format savenumx savenumy commax9.5;
run;

proc contents data=fakedata;
  title 'check variables type -- new variables are character';
run;

proc print data=fakedata;
  title 'Original numbers show period, character versions show comma';
format savenumx savenumy 9.5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 19:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725249#M225228</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-03-10T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725254#M225230</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Mikkel_madse&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;... Both variables are of course numeric.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Numbers contain neither commas or periods, so there is nothing to translate from/to.&lt;/P&gt;
&lt;P&gt;To change how the values are displayed you just need to change the format used to display them.&amp;nbsp; The COMMAX format will display the decimal point as a comma instead of period.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format x y commax10.5 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 19:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725254#M225230</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-10T19:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725258#M225232</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;P&gt;Please post the complete log from your data step.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 20:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725258#M225232</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-10T20:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725270#M225238</link>
      <description>If it's already numeric, then you want to change the appearance of the period to a comma - unless you need to plot or map it somehow. But you can change the format instead of changing the value, as Tom indicates.</description>
      <pubDate>Wed, 10 Mar 2021 21:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725270#M225238</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-10T21:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change dot to comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725369#M225300</link>
      <description>&lt;P&gt;Thank you, everyone!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to replace the dot with a comma before import to QGIS for geo-analysis.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 08:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-dot-to-comma/m-p/725369#M225300</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-03-11T08:24:12Z</dc:date>
    </item>
  </channel>
</rss>

