<?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: SAS numeric length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498547#M132516</link>
    <description>&lt;P&gt;You should be able to go back to your original data source and retrieve the 11 digit number.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Sep 2018 19:40:02 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-09-24T19:40:02Z</dc:date>
    <item>
      <title>SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498543#M132514</link>
      <description>&lt;P&gt;Hi SAS users-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I originally had a numeric variable, SubjectID, that had a length of 6 but the value displayed was up to&amp;nbsp;11 digits.&amp;nbsp; I accidentally thought this numeric variable was actually a character, so I converted it to numeric even though it was already numeric. (See SAS code below for my conversion step.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This resulted in truncated values of the original variable, e.g. 20000000021 is now 20000000.&amp;nbsp; Is there anyway to retrieve the original value of SubjectID?&amp;nbsp; Or is it gone for good?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data convert;&lt;/P&gt;&lt;P&gt;set have (rename=(&lt;SPAN&gt;SubjectID=chrx_SubjectID));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;length &lt;SPAN&gt;SubjectID&amp;nbsp;&lt;/SPAN&gt;8.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SubjectID&lt;/SPAN&gt;=input(chrx_&lt;SPAN&gt;SubjectID&lt;/SPAN&gt;,8.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498543#M132514</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2018-09-24T19:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498547#M132516</link>
      <description>&lt;P&gt;You should be able to go back to your original data source and retrieve the 11 digit number.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498547#M132516</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-24T19:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498553#M132520</link>
      <description>&lt;P&gt;By my original data source, are you referring to the "Have" dataset?&amp;nbsp; If so, that dataset is no longer available. The only one I have access to is the 'convert' dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498553#M132520</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2018-09-24T19:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498556#M132521</link>
      <description>&lt;P&gt;If you ran that code then your original value is in the variable CHRX_SUBJECTID.&lt;/P&gt;
&lt;P&gt;What happens if you run this test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set convert obs=4 ;
  put SubjectID= chrx_SubjectID= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498556#M132521</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-24T19:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498561#M132523</link>
      <description>&lt;P&gt;That sounds like a pretty dangerous combination:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Make some changes to the data&lt;/LI&gt;
&lt;LI&gt;Don't check to see whether the changes worked properly&lt;/LI&gt;
&lt;LI&gt;Get rid of the original data&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Hopefully you can learn from this for next time.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498561#M132523</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-24T19:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS numeric length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498599#M132544</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9463"&gt;@sophia_SAS&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to your initial surprise about the length of SubjectID: The length of a numeric variable does &lt;EM&gt;not&lt;/EM&gt; specify the maximum number of &lt;EM&gt;digits&lt;/EM&gt;, but the number of &lt;EM&gt;bytes&lt;/EM&gt; used to store the numeric values internally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The length limits the &lt;EM&gt;precision&lt;/EM&gt; to which numbers can be stored. In particular, there are "largest integers that can be safely stored in a given length": see the table in "&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1ikmedbli0rz2n1de001ryz895o" target="_blank"&gt;Numerical Accuracy in SAS Software&lt;/A&gt;."&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;As you see in the table, on Windows and Unix systems length 6 (bytes) is sufficient for integers with 11 digits (and even for a limited range of 12-digit integers), whereas 5 bytes or less would be insufficient. An insufficient length means that certain integers beyond the limit are &lt;EM&gt;rounded&lt;/EM&gt; to multiples of 2, 4, 8, 16, ... (powers of 2) and the effects on non-integer values are even more difficult to deal with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your program (but only with a semicolon after the LENGTH statement, rather than a period) has created the "truncated" versions of the original values in the following way:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The numeric values in chrx_SubjectID were internally converted to character values (see the corresponding log message if you haven't discarded it) using the BEST12. format because the first argument of the INPUT function&amp;nbsp;must be character.&lt;/LI&gt;
&lt;LI&gt;The resulting right-aligned (!) strings of length 12 were read with the 8. informat, which would read the leading blank plus the first &lt;EM&gt;seven&lt;/EM&gt; digits&amp;nbsp;of a 11-digit string. Hence, the result for 20000000021 would normally be 2000000, not 2000000&lt;STRONG&gt;0&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;To resolve the issue&lt;/STRONG&gt; (as Tom has already mentioned), it should be no problem to drop the newly created variable SubjectID and rename chrx_SubjectID back to SubjectID:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set convert;
drop SubjectID;
rename chrx_SubjectID=SubjectID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 21:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-numeric-length/m-p/498599#M132544</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-24T21:27:45Z</dc:date>
    </item>
  </channel>
</rss>

