<?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: Measure the max length of decimal places in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258263#M49710</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the detailed explanation. It makes sense.&lt;BR /&gt;I did overlook the NOTE, ^_^.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2016 16:48:05 GMT</pubDate>
    <dc:creator>jiangmi</dc:creator>
    <dc:date>2016-03-22T16:48:05Z</dc:date>
    <item>
      <title>Measure the max length of decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258237#M49703</link>
      <description>&lt;P&gt;Hi, All,&lt;/P&gt;
&lt;P&gt;I ran into a confusion situation when trying to measure the max decimal places in a data. The problem is demostrated in the following sample. Basically, I have a variable (pct) that has a very long decimal place (12). The first attempt to measure its decimal place returned 10. After I re-formated it into a numeric 20.12, the second attempt still gives out a 10. If you run 'proc contents', the format shows 20.12.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, I don't need data with&amp;nbsp;that many decimal places in my work. &amp;nbsp;I just want to know why this happened and how to measure the max decimal places accurately if needed. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*1. the sample data*/&lt;BR /&gt;data have;&lt;BR /&gt;pct=0.123456789123;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/*2. check the length */&lt;BR /&gt;data checkthelength;&lt;BR /&gt;set have;&lt;BR /&gt;sca=scan(pct,2,".");&lt;BR /&gt;len=lengthn(scan(pct,2,"."));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/*3. Reformat PCT*/&lt;BR /&gt;proc sql;&lt;BR /&gt;alter table checkthelength &lt;BR /&gt;modify pct format= 20.12&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;/*4. check the length again*/&lt;BR /&gt;data checkthelength2;&lt;BR /&gt;set checkthelength;&lt;BR /&gt;sca2=scan(pct,2,".");&lt;BR /&gt;len2=lengthn(scan(pct,2,"."));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258237#M49703</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2016-03-22T15:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Measure the max length of decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258241#M49705</link>
      <description>&lt;P&gt;This works finne for me:&lt;/P&gt;
&lt;PRE&gt;data want;
  format val 20.12;
  val=0.123456789123;
  len=lengthn(scan(put(val,20.12),2,'.'));
run;&lt;/PRE&gt;
&lt;P&gt;I assume that when you convert to text you are truncating somehow, check your put() function.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 15:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258241#M49705</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-22T15:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Measure the max length of decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258258#M49709</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3835"&gt;@jiangmi﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The explanation for your results is:&lt;/P&gt;
&lt;P&gt;SCAN is a character function, i.e. it actually expects a character value as its first argument. Just for your convenience, SAS automatically converts a numeric first argument to a character value before processing it. This is documented in the log by a message like&lt;/P&gt;
&lt;PRE&gt;NOTE: Numeric values have been converted to character values at the places given by ...&lt;/PRE&gt;
&lt;P&gt;You didn't ignore this log message, did you? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For automatic numeric-to-character conversion SAS uses a default format:&amp;nbsp;BEST12. This is independent of a numeric format that you might have associated with a numeric variable, i.e., your ALTER/MODIFY statement could not influence the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BEST12. formatted value of 0.123456789123 is, of course, 0.1234567891, hence the 10 decimal places.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 16:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258258#M49709</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-22T16:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Measure the max length of decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258263#M49710</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the detailed explanation. It makes sense.&lt;BR /&gt;I did overlook the NOTE, ^_^.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 16:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258263#M49710</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2016-03-22T16:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Measure the max length of decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258270#M49711</link>
      <description>&lt;P&gt;Another important point is that the concept of the "number of decimal places" of the value of a numeric variable in SAS is more difficult than you might think. Whenever you display such a value (be it with a PUT statement, PROC PRINT, VIEWTABLE, ...) you see a &lt;U&gt;formatted&lt;/U&gt; value. If you didn't specify the format, SAS chooses one for you (and it's sometimes hard to say which one exactly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The formatting is necessary because numeric values are stored internally in what is called a &lt;EM&gt;binary floating-point representation&lt;/EM&gt; (see &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank" rel="nofollow"&gt;Numerical Accuracy in SAS Software&lt;/A&gt; for details), which is ideal for the computer, but hard to read for humans. The exact decimal value corresponding to a particular binary floating-point representation can easily have more decimal places than any of the usual SAS formats (even the long ones such as BEST32.) could display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the question of the number of decimal places should ideally refer to a specific format (like 20.12 in your example), which makes the answer easy, but also somewhat unsatisfactory, because the choice of the format is arbitrary to some extent.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 17:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Measure-the-max-length-of-decimal-places/m-p/258270#M49711</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-22T17:06:15Z</dc:date>
    </item>
  </channel>
</rss>

