- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
how about this.
data test;
SKUNEW='002500000000011205';
SKUNEW2=input(SKUNEW,20.);
format SKUNEW2 20.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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):