BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vkumbhakarna
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.

Reeza
Super User

I don't believe this is a SAS specific issue, as I've seen it in Excel and R recently as well.

jakarman
Barite | Level 11

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

---->-- ja karman --<-----

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 954 views
  • 7 likes
  • 4 in conversation