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;
how about this.
data test;
SKUNEW='002500000000011205';
SKUNEW2=input(SKUNEW,20.);
format SKUNEW2 20.;
run;
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?
@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.
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.
Just to address two possible reasons for this problematic character-to-numeric conversion:
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):
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!
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.
Ready to level-up your skills? Choose your own adventure.