- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I want to convert a character variable to numeric.
The character variable as shown in this example contains occurrences that are long.
After conversion, the numerical result obtained is not the same with that which is the one in the varaible character.
How can I get the same numbers in both formats?
Thank you
data char_to_num;
/*Conversion Charatere to numeric */
x_char1 = "123456789123456789123456123456";
x_num1 = input(x_char1,best32.);
format x_num1 best32.2;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@mansour_ib_sas wrote:
Hello,
I want to convert a character variable to numeric.
The character variable as shown in this example contains occurrences that are long.
After conversion, the numerical result obtained is not the same with that which is the one in the varaible character.
How can I get the same numbers in both formats?Thank you
data char_to_num; /*Conversion Charatere to numeric */ x_char1 = "123456789123456789123456123456"; x_num1 = input(x_char1,best32.); format x_num1 best32.2; run;
You cannot.
SAS stores numbers using 8 byte floating point values. You can only store about 15 digits of precision using that format.
What calculations you going to do with such a large number anyway that needs to preserve such a large level of precision?
If it is an identifier then keep it as a character string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@mansour_ib_sas wrote:
Hello,
I want to convert a character variable to numeric.
The character variable as shown in this example contains occurrences that are long.
After conversion, the numerical result obtained is not the same with that which is the one in the varaible character.
How can I get the same numbers in both formats?Thank you
data char_to_num; /*Conversion Charatere to numeric */ x_char1 = "123456789123456789123456123456"; x_num1 = input(x_char1,best32.); format x_num1 best32.2; run;
You cannot.
SAS stores numbers using 8 byte floating point values. You can only store about 15 digits of precision using that format.
What calculations you going to do with such a large number anyway that needs to preserve such a large level of precision?
If it is an identifier then keep it as a character string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for Ansewer.
It's for If identifier.
I did an itirative test, and I arrived at a precision level of 17
data char_to_num;
/*Conversion Charatere to numeric */
x_char1 = "123456789123456789123456123456";
x_num1 = input(x_char1,17.);
format x_num1 best32.2;
run;