Hi everyone,
This is my first post with SAS Support communities, so please bear with me and pardon my misgivings.
I ran into an issue lately where I was trying to convert a character variable into a numeric variable while extracting data from a dataset. The character variable was a 18 digit long numeric value stored as character. So, when I tried importing the variable and converting it into numeric using the input function, only the first 16 digits were getting converted successfully and the last 2 digits were getting arbitrarily random values. So, I took the empirical approach and devised the following simple code to check is SAS is able to process the numericals upto 10^18 numerical precision, and I found that last 2 digits were always lost. Can you please help me understand if my conclusion is correct? Is SAS unable to handle numerical variables beyond 10^16 value? Please adivse.
Code:
214 data _null_ ;
215 do i=1 to 17 ;
216 big_num = 10**i + 1 ;
217 put big_num best18. +2 i 2. ;
218 end ;
219 run ;
Result:
11 1
101 2
1001 3
10001 4
100001 5
1000001 6
10000001 7
100000001 8
1000000001 9
10000000001 10
100000000001 11
1000000000001 12
10000000000001 13
100000000000001 14
1000000000000001 15
10000000000000000 16
100000000000000000 17
For observation 16 and 17 it can be seen that the numerical precision is lost. Please advise how can I go around this issue? Thanks in advance.
16 data _null_;
17 max=constant('exactint');
18 put max=comma21.;
19 run;
max=9,007,199,254,740,992
Easiest way to deal with it is to NOT convert your character variable into an numeric.
16 data _null_;
17 max=constant('exactint');
18 put max=comma21.;
19 run;
max=9,007,199,254,740,992
Easiest way to deal with it is to NOT convert your character variable into an numeric.
I don't believe this is a SAS specific issue, as I've seen it in Excel and R recently as well.
This is indeed no SAS specific issue. It is related to what processor you are using.
SAS(R) 9.2 Language Reference: Concepts, Second Edition (precision) The floating point area are processor instrcutions.
Do not forget SAS(R) 9.4 DS2 Language Reference, Second Edition as there the approach is differtent and the limitations are different.
http://blogs.sas.com/content/sastraining/2013/04/08/jedi-sas-tricks-finding-tattoine-with-ds2/
Floating point - Wikipedia, the free encyclopedia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.