<?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: Char to numeric with decimal points in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751253#M236460</link>
    <description>&lt;P&gt;There is a limit to the number of decimal digits that can be exactly represented (without gaps) using the binary floating point representation SAS (and most software) use to store numbers.&amp;nbsp; But your example strings are no where near that limit.&lt;/P&gt;
&lt;PRE&gt; -259328.943733
-35860.382829
0 &lt;/PRE&gt;
&lt;P&gt;So to convert those strings into numbers use the normal numeric informat.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;calc_rslt_num = input(calc_rslt,32.); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Note do NOT include a number of decimal places in the informat&lt;/STRONG&gt;, unless you know that the periods have been removed to save space. Otherwise if you use 22.6 informat and the string does not contain a period the number is divided by 10**6 to place the implied decimal point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value to display with 6 digits to the right of the decimal place the use a format when displaying the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format calc_rslt_num 22.6 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Jun 2021 13:57:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-06-30T13:57:55Z</dc:date>
    <item>
      <title>Char to numeric with decimal points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751196#M236439</link>
      <description>&lt;P&gt;I've a character variable called calc_rslt and it has values like &amp;nbsp;-259328.943733,-35860.382829,0. Now I want to convert it to numeric without rounding off the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I tried with the Format 22.6 in the Input function, I could see it is rounding off the value. e.g. -259328.943733 is rounded to -259328.9437.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;calc_rslt_num = input(calc_rslt,22.6); &lt;/PRE&gt;
&lt;P&gt;Also if it is 0 (character)&amp;nbsp;in the Input value then I want to convert it to 0.000000 (numeric). It is also not working when I tried with if then clause as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If value=0 then value=0.000000&lt;/PRE&gt;
&lt;P&gt;Desired results for the provided values should be -259328.943733,-35860.382829,0.000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 12:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751196#M236439</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-30T12:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric with decimal points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751197#M236440</link>
      <description>&lt;P&gt;When you do this creation of a new numeric variable, it has a default format of best12. However, the full decimal places are there, which can be seen by changing the format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    calc_rslt='-259328.943733';
    calc_rslt_num = input(calc_rslt,22.6); 
    format calc_rslt_num best24.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, this begs the question about why you have non-integer numbers in a character variable, which doesn't seem like a good thing to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 12:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751197#M236440</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-30T12:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric with decimal points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751212#M236446</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;how about my other question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if it is 0&amp;nbsp;after converting from character to numeric&amp;nbsp;then I want to convert it to 0.000000 (numeric). It is also not working when I tried with if then clause as shown in the Initial post&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 13:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751212#M236446</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-06-30T13:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric with decimal points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751214#M236447</link>
      <description>&lt;P&gt;Internally, there is no difference between 0 and 0.000000, these are the same number. The only difference is the appearance, so you need to find a format (which has the effect of changing the appearance) that works on both&amp;nbsp;-259328.943733 and 0.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 13:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751214#M236447</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-30T13:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Char to numeric with decimal points</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751253#M236460</link>
      <description>&lt;P&gt;There is a limit to the number of decimal digits that can be exactly represented (without gaps) using the binary floating point representation SAS (and most software) use to store numbers.&amp;nbsp; But your example strings are no where near that limit.&lt;/P&gt;
&lt;PRE&gt; -259328.943733
-35860.382829
0 &lt;/PRE&gt;
&lt;P&gt;So to convert those strings into numbers use the normal numeric informat.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;calc_rslt_num = input(calc_rslt,32.); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Note do NOT include a number of decimal places in the informat&lt;/STRONG&gt;, unless you know that the periods have been removed to save space. Otherwise if you use 22.6 informat and the string does not contain a period the number is divided by 10**6 to place the implied decimal point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the value to display with 6 digits to the right of the decimal place the use a format when displaying the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format calc_rslt_num 22.6 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Jun 2021 13:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-to-numeric-with-decimal-points/m-p/751253#M236460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-30T13:57:55Z</dc:date>
    </item>
  </channel>
</rss>

