<?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: How to change commas to periods for numbers with decimals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609751#M177523</link>
    <description>&lt;P&gt;Do you have other text in that field?&amp;nbsp; Do you ever have values large enough that they also have separators between thousands and hundreds?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then just replace the comma with period.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;temp=translate(temp,'.',',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you also have values like 1.234,56 then you could test if the last one is a comma and only then reverse them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if char(temp,length(temp)-2)=',' then temp=translate(temp,',.','.,');&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Dec 2019 17:51:22 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-12-05T17:51:22Z</dc:date>
    <item>
      <title>How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609743#M177520</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with a temperature variable in Celsius. For some values the decimal point is a comma instead, so I'll need to convert them to a period to run other codes. I could do a simple "if Temp = 37,0 then Temp = 37.0" but it's a large database I'd like to automate this at the start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data set below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Work.Have;
  Input PatientId $ AgeMo Temp $;
    Datalines;
	0001 11 37.9
	0002 9  38.7
	0003 44 38,1
	0004 30 37.7
	0005 19 37,5
	;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 17:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609743#M177520</guid>
      <dc:creator>ty_chv</dc:creator>
      <dc:date>2019-12-05T17:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609751#M177523</link>
      <description>&lt;P&gt;Do you have other text in that field?&amp;nbsp; Do you ever have values large enough that they also have separators between thousands and hundreds?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then just replace the comma with period.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;temp=translate(temp,'.',',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you also have values like 1.234,56 then you could test if the last one is a comma and only then reverse them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if char(temp,length(temp)-2)=',' then temp=translate(temp,',.','.,');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Dec 2019 17:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609751#M177523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-05T17:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609753#M177524</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Work.Have;
  Input PatientId $ AgeMo Temp $;
  Temp_n = input(translate(Temp,",","."), comma8.1);
  drop Temp;
  rename Temp_n = Temp;
    Datalines;
	0001 11 37.9
	0002 9  38.7
	0003 44 38,1
	0004 30 37.7
	0005 19 37,5
	;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Dec 2019 17:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609753#M177524</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-05T17:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609766#M177532</link>
      <description>&lt;P&gt;Thanks for the reply, this fixed the comma issue but now there's a new one. Variables without any decimals are assigned a period (40 -&amp;gt; 4.0). I didn't include those without decimals before, below is an updated code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Work.Have;
  Input PatientId $ AgeMo Temp $;
  Temp_n = input(translate(Temp,",","."), comma8.1);
  Drop Temp;
  Rename Temp_n = Temp;
    Datalines;
	0001 11 37.9
	0002 9  38.7
	0003 44 38,1
	0004 30 37.7
	0005 19 37,5
	0006 20 40
	0007 10 39
	;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which gives this output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs PatientId AgeMo Temp1234567 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;0001&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;37.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0002&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;38.7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0003&lt;/TD&gt;&lt;TD&gt;44&lt;/TD&gt;&lt;TD&gt;38.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0004&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;37.7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0005&lt;/TD&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;37.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0006&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;4.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0007&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;3.9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609766#M177532</guid>
      <dc:creator>ty_chv</dc:creator>
      <dc:date>2019-12-05T18:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609767#M177533</link>
      <description>DO NOT INCLUDE DECIMAL WIDTH IN AN INFORMAT!!!!&lt;BR /&gt;DO NOT INCLUDE DECIMAL WIDTH IN AN INFORMAT!!!!&lt;BR /&gt;DO NOT INCLUDE DECIMAL WIDTH IN AN INFORMAT!!!!&lt;BR /&gt;That will divide any values without decimal points (exact integers) by the specified power of 10.&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609767#M177533</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-05T18:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609768#M177534</link>
      <description>Thanks for the reply. No values as in the second case so I went with the first solution. Now have a new issue for numbers with no decimals though</description>
      <pubDate>Thu, 05 Dec 2019 18:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609768#M177534</guid>
      <dc:creator>ty_chv</dc:creator>
      <dc:date>2019-12-05T18:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609772#M177538</link>
      <description>New issue was caused by adding the input statement below. Used exactly as the first one and it worked.&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Thu, 05 Dec 2019 18:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609772#M177538</guid>
      <dc:creator>ty_chv</dc:creator>
      <dc:date>2019-12-05T18:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to change commas to periods for numbers with decimals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609774#M177539</link>
      <description>&lt;P&gt;You do not want to include decimal width in the informat specification, unless you want SAS to divide text without the decimal point by that power of ten.&amp;nbsp; Do not translate the periods to commas (unless perhaps your SAS session is one where that is what the COMMA informat wants).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input PatientId $ AgeMo Temp $;
  Temp_n = input(translate(Temp,".",","), comma8.);
  drop Temp;
  rename Temp_n = Temp;
datalines;
0001 11 37.9
0002 9  38.7
0003 44 38,1
0004 30 37.7
0005 19 37,5
0006 20 40
0007 10 39
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       Patient    Age
Obs      Id        Mo    Temp

 1      0001       11    37.9
 2      0002        9    38.7
 3      0003       44    38.1
 4      0004       30    37.7
 5      0005       19    37.5
 6      0006       20    40.0
 7      0007       10    39.0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-commas-to-periods-for-numbers-with-decimals/m-p/609774#M177539</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-05T18:55:24Z</dc:date>
    </item>
  </channel>
</rss>

