<?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: Number of Decimal Places in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77941#M22506</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to everyone for your help with this!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Aug 2012 11:51:41 GMT</pubDate>
    <dc:creator>fastb</dc:creator>
    <dc:date>2012-08-02T11:51:41Z</dc:date>
    <item>
      <title>Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77933#M22498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anyone know of a procedure where the input is a number and the output is the number of decimal places in that number?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, if I enter 10.8605, I need the output to be either 0.0001 or 4.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 12:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77933#M22498</guid>
      <dc:creator>fastb</dc:creator>
      <dc:date>2012-07-30T12:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77934#M22499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, try a simple data step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;a=10.8605;&lt;/P&gt;&lt;P&gt;b1=lengthn(strip(a))-lengthn(strip(floor(a)))-1;&lt;/P&gt;&lt;P&gt;b2=1/10**b1;&lt;/P&gt;&lt;P&gt;put b2= b1=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 12:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77934#M22499</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-07-30T12:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77935#M22500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This shoukld work as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA one ;&lt;BR /&gt;INPUT v1 ;&lt;BR /&gt;CARDS ;&lt;BR /&gt;10.1234&lt;BR /&gt;123.125&lt;BR /&gt;1.123456&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set one;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; first = substr(v1, 1, index(v1, '.') - 1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; second = left(substr(v1, index(v1, '.') + 1));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; remainder = LENGTH(second);&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 13:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77935#M22500</guid>
      <dc:creator>robby_beum</dc:creator>
      <dc:date>2012-07-30T13:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77936#M22501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you interested in number of digits in string or number of significant digits?&amp;nbsp; e.g., given the following numbers, what result would you expect for each?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;125.&lt;/P&gt;&lt;P&gt;125.0&lt;/P&gt;&lt;P&gt;125.00&lt;/P&gt;&lt;P&gt;125.000&lt;/P&gt;&lt;P&gt;125.0000&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 13:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77936#M22501</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-07-30T13:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77937#M22502</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Input&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Result&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;125.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.0 or 0&lt;/P&gt;&lt;P&gt;125.0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.1 or 1&lt;/P&gt;&lt;P&gt;125.00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 or 2&lt;/P&gt;&lt;P&gt;125.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.001&amp;nbsp; or 3&lt;/P&gt;&lt;P&gt;125.0000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0001 or 4&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 13:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77937#M22502</guid>
      <dc:creator>fastb</dc:creator>
      <dc:date>2012-07-30T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77938#M22503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then, whether you use Haikuo's or Robby's suggested code, make sure that your input variable is a character variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 14:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77938#M22503</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-07-30T14:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77939#M22504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... with all those zeroes (e.g. 125.0000) there won't be any decimal places since 125.0000 is a really an integer, yes/no?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;input x @@;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;format x 10.4;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;125 125.1 125.01 125.001 125.0001 125.0000&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;set x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;d = lengthn(scan(cat(x),2,'.'));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x&amp;nbsp;&amp;nbsp;&amp;nbsp; d&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.0000&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.1000&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.0100&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.0010&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.0001&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 125.0000&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2012 14:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77939#M22504</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-07-30T14:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77940#M22505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding to Arthur's advice: even if you don't want to count trailing zeroes, the methods above should ONLY be used on character inputs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On my computer, all three of the code examples above give the wrong answer for an input of 0.000001 or 10000000.1234. The reason for this is that their inputs are defined as numeric by default. When you perform a string operation (STRIP, INDEX, SUBSTR, CAT) on a numeric variable you force SAS to do an implicit conversion from num to char, and the format it selects may not be the one you're expecting. Watch out for that "NOTE: Character values have been converted to numeric values" in the log.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case, a numeric value of 0.000001 gets converted to "1E-6" not "0.000001" and 10000000.1234 gets converted to "1000000.123", both of which lead to the wrong answer. Two of these examples assume that there will be a decimal point, and so they give the wrong answer for an integer input.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Possibly worth adding a check in the program to return a warning/error message if this is supplied with numeric input, since it would be a VERY easy mistake to make.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 06:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77940#M22505</guid>
      <dc:creator>GeoffreyBrent</dc:creator>
      <dc:date>2012-07-31T06:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Decimal Places</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77941#M22506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to everyone for your help with this!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 11:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Decimal-Places/m-p/77941#M22506</guid>
      <dc:creator>fastb</dc:creator>
      <dc:date>2012-08-02T11:51:41Z</dc:date>
    </item>
  </channel>
</rss>

