BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

I'm trying to convert the following number to numeric but it is producing the value in exponential format. I need the value in numeric like how how it was in character without rounding and exponential format. Any help?

 

data test;
SKUNEW='002500000000011205';
SKUNEW2=input(SKUNEW,20.);
run;
5 REPLIES 5
japelin
Rhodochrosite | Level 12

how about this.

data test;
SKUNEW='002500000000011205';
SKUNEW2=input(SKUNEW,20.);
format SKUNEW2 20.;
run;
Kurt_Bremser
Super User

This conversion is not possible in a reliable way. Because of the way numeric data is stored, not more than 15 decimal digits can be precisely stored.

Which statistic or calculation do you intend to do with these numbers?

PaigeMiller
Diamond | Level 26

@David_Billa wrote:

I'm trying to convert the following number to numeric but it is producing the value in exponential format. I need the value in numeric like how how it was in character without rounding and exponential format.

 

In addition to what @Kurt_Bremser said, this is obviously not a number (despite the fact that it only contains digits), it is some sort of ID variable, and there's no real reason to have this as a number. It's not like you're going to find an average of the ID values. So, your attempt to turn it into a number seems to be misguided. Leave it as character.

--
Paige Miller
Astounding
PROC Star

I agree 100% with the advice that says don't do it.  You have decades of expert advice saying this ... SAS will not accurately convert long values to numeric.

 

Within the SAS family of products, DS2 will let you get up to 19 digits, but not 20.  But I doubt you want to learn another programming language just to convert your data.

 

While none of the experts (myself included) think this is a good idea, you could still do something in SAS.  You could create two numeric variables instead of one.  Then modify your programming to utilize both variables.  Creating two is easy:

 

part1 = input(SKUNew, 10.);

part2 = input(substr(SKUNew,11), 10.);

 

Of course, subsequent programming with two variables instead of one is harder but can be done. 

FreelanceReinh
Jade | Level 19

Just to address two possible reasons for this problematic character-to-numeric conversion:

  • Do you work with software like an external database where such values are stored as numeric and you need to compare SKUNEW to those values?
    Then convert those external values to character appropriately (i.e., considering leading zeros) before the comparison.

  • Do you really need to perform some numeric operation on SKUNEW (e.g., compute a checksum of some sort)?
    This can be done using the existing digit strings in SKUNEW. See Re: Mod function with big number for an example.

 

So, again, the conclusion is (to let SAS speak for itself):

320   data _null_;
321   if input('009500000000011205',20.)=009500000000011204 then put 'Leave it as character!';
322   run;

Leave it as character!
NOTE: DATA statement used (Total process time):

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 750 views
  • 4 likes
  • 6 in conversation