<?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: Numeric variable adding extra digits in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196626#M36931</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're right--I invented those examples, and now that I look at it more closely, the values ending in .0 or .5 were actually converted correctly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing my length statement to 8. fixed the issue. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Jul 2015 19:48:52 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2015-07-06T19:48:52Z</dc:date>
    <item>
      <title>Numeric variable adding extra digits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196623#M36928</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;I have a dataset with two character variables (composed entirely of numbers). Each person will have a value for Char_var1 or Char_var2, but not both. I created a variable that basically combines the values of Char_var1 and Char_var2, so everyone will have a value for the combined variable. I wanted the combination variable to be numeric so I added a length statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;length combined_var 3.;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if char_var1 ne " " then combined_var=char_var1;&lt;/P&gt;&lt;P&gt;else if char_var1=" " then combined_var=char_var2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that in the resulting dataset, the combined_var has added several digits to each value:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Char_var1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Char_var2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Combined_var&lt;/P&gt;&lt;P&gt;1.5&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.51493&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6.3&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; 6.32139&lt;/P&gt;&lt;P&gt;7.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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7.01493&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure where the digits came from--the source data has only one digit after the decimal point for Char_var1 and Char_var2. Any help is much appreciated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 18:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196623#M36928</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-07-06T18:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric variable adding extra digits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196624#M36929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Walternate,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of allowing SAS to convert that character value into a number for you, you should probably convert it explicitly with an INPUT function.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;combined_var=input(char_var1, 4.1); /* read in to first decimal precision */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;More on this topic here:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&lt;A href="http://blogs.sas.com/content/sgf/2015/05/01/converting-variable-types-do-i-use-put-or-input/" title="http://blogs.sas.com/content/sgf/2015/05/01/converting-variable-types-do-i-use-put-or-input/"&gt;http://blogs.sas.com/content/sgf/2015/05/01/converting-variable-types-do-i-use-put-or-input/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;On the Fringe,&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;Chris&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 19:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196624#M36929</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2015-07-06T19:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric variable adding extra digits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196625#M36930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The culprit here is the LENGTH statement.&amp;nbsp; SAS stores numerics in a converted format, storing the value (not the digits themselves).&amp;nbsp; Decimal fractions can't be stored exactly, and so should use a length of 8 (not 3) for maximum possible precision.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even with that in mind, it's surprising that 1.5 and 7.0 can't be stored exactly.&amp;nbsp; Those are values that a length of 3 should be able to store with no trouble.&amp;nbsp; 6.3 is another story.&amp;nbsp; Like trying to store 1/3 in a decimal system, there's no exact equivalent to 6.3 in a binary system.&amp;nbsp; But there are very short binary equivalents to 1.5 and 7.0 in binary (1.1, and 111).&amp;nbsp; Are those real-life examples, or are they typed in just to illustrate the issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 19:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196625#M36930</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-07-06T19:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric variable adding extra digits</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196626#M36931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're right--I invented those examples, and now that I look at it more closely, the values ending in .0 or .5 were actually converted correctly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Changing my length statement to 8. fixed the issue. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 19:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-variable-adding-extra-digits/m-p/196626#M36931</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-07-06T19:48:52Z</dc:date>
    </item>
  </channel>
</rss>

