DATA Step, Macro, Functions and more

Last two digits changed when converting character value into numeric value

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Last two digits changed when converting character value into numeric value


I have a character variable with values of numbers (17-18 digits). I wanted to convert them into numeric. But the last two digits have changed for some reason.

The sas code I used is:

data convert;

set original;

numeric=input(character 18.0);

format numeric 18.0;

run;


Accepted Solutions
Solution
‎10-24-2013 09:57 AM
Super Contributor
Posts: 253

Re: Last two digits changed when converting character value into numeric value

Posted in reply to cindyforest7

Depending on your operating system, SAS can only handle around 15 digits of precision with a numeric (in Windows, out of 64 bits for an 8 byte number, 1 is the sign and 11 are the exponent, meaning 52 bits are available for the mantissa (the precise digits) - around 4x10^15. Any number over 4x10^15 will begin losing precision.  See SAS(R) 9.2 Language Reference: Concepts, Second Edition for more information.

View solution in original post


All Replies
Frequent Contributor
Posts: 106

Re: Last two digits changed when converting character value into numeric value

Posted in reply to cindyforest7

can't use more then 16 digits. refer this: http://support.sas.com/techsup/technote/ts654.pdf

Super Contributor
Posts: 253

Re: Last two digits changed when converting character value into numeric value

Posted in reply to pradeepalankar

Even 16 digits is not safe.  2^53 (around 4x10^15) is the maximum storable number with full precision; so some Visa numbers may be storable, but no Mastercard numbers (5x10^15).  This of course is often relevant with credit card numbers simply because they are right at that point of precision loss.

Solution
‎10-24-2013 09:57 AM
Super Contributor
Posts: 253

Re: Last two digits changed when converting character value into numeric value

Posted in reply to cindyforest7

Depending on your operating system, SAS can only handle around 15 digits of precision with a numeric (in Windows, out of 64 bits for an 8 byte number, 1 is the sign and 11 are the exponent, meaning 52 bits are available for the mantissa (the precise digits) - around 4x10^15. Any number over 4x10^15 will begin losing precision.  See SAS(R) 9.2 Language Reference: Concepts, Second Edition for more information.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 732 views
  • 6 likes
  • 3 in conversation