<?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 convert to char from numeric without losing decimals in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196307#M2547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can't fix set number of numbers and not use it for all the values like that.&amp;nbsp; So, to fix it to two decimal output you would use z8.2, however the upshot of this is that 3 would become 3.00.&amp;nbsp; That is I am afraid consistency.&amp;nbsp; If you don't want that effect then you will have to pad it yourself in the text field, ie.&lt;/P&gt;&lt;P&gt;temp=strip(substr(index(text,".")+1));&amp;nbsp; /* This gets you the decimal part */&lt;/P&gt;&lt;P&gt;if length(strip(temp)) &amp;lt; 2 then text=cats(strip(text),repeat("0",length(temp)-1);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Mar 2015 20:06:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-03-06T20:06:32Z</dc:date>
    <item>
      <title>How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196303#M2543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a numeric variable x and i tried to convert to character using: put (x, best32.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, x can have values like 3, 3.0, 3.02 etc...upto 2 decimal places.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to keep the format as is..i.e 3 --&amp;gt;3, 3.0 --&amp;gt; 3.0 and so on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently, with my code, it is outputting everything as 1 decimal places...and dropping the second decimal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks very much&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 17:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196303#M2543</guid>
      <dc:creator>eagles_dare13</dc:creator>
      <dc:date>2015-03-06T17:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196304#M2544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just specify the number of decimal places:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3.01; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3.1; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length text $10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; text=strip(put(num,best8.2));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 17:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196304#M2544</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-03-06T17:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196305#M2545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It may be that&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;with my code, it is outputting everything as 1 decimal&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;is due to the method. Some procedures round for simplicity. Show how you are creating that output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are printing the output then the format is likely an issue. Try assigning a format that forces 2 decimals such as&lt;/P&gt;&lt;P&gt;Format variable f8.2 ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the default format is something like best8. and you have values of 12345678.99 then only 8 digits are likely to display and the .99 wouldn't be seen.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 17:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196305#M2545</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-03-06T17:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196306#M2546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, but 3.10 is coming as 3.1, the last 0 is getting dropped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3.01; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; num=3.10; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length text $10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; text=strip(put(num,best7.2));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 18:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196306#M2546</guid>
      <dc:creator>eagles_dare13</dc:creator>
      <dc:date>2015-03-06T18:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196307#M2547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can't fix set number of numbers and not use it for all the values like that.&amp;nbsp; So, to fix it to two decimal output you would use z8.2, however the upshot of this is that 3 would become 3.00.&amp;nbsp; That is I am afraid consistency.&amp;nbsp; If you don't want that effect then you will have to pad it yourself in the text field, ie.&lt;/P&gt;&lt;P&gt;temp=strip(substr(index(text,".")+1));&amp;nbsp; /* This gets you the decimal part */&lt;/P&gt;&lt;P&gt;if length(strip(temp)) &amp;lt; 2 then text=cats(strip(text),repeat("0",length(temp)-1);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Mar 2015 20:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196307#M2547</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-03-06T20:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert to char from numeric without losing decimals</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196308#M2548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The number 3.1 and the number 3.10 are the exact same number.&amp;nbsp; If you want to distinguish between them you will need to store them differently.&lt;/P&gt;&lt;P&gt;You could store them in a character variable.&lt;/P&gt;&lt;P&gt;You could store additional variable(s)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Perhaps store the display format you want :&amp;nbsp; (3.1, 'F3.1') and (3.10,'F4.2')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Or just the number of decimal places (3.1, 1) and (3.10, 2).&lt;/P&gt;&lt;P&gt;You could store them in different variables which could have their own formats attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp; DECIMAL1 = 3.1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DECIMAL2 = 3.1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format decimal1 F3.1 decimal2 F4.2 ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Mar 2015 00:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/How-to-convert-to-char-from-numeric-without-losing-decimals/m-p/196308#M2548</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-07T00:04:02Z</dc:date>
    </item>
  </channel>
</rss>

