Hi, I have a dataset where it has a variable that is a character but the value is in a numeric format. Thus, I transformed it from char to num by doing the following logit. However, after the transformation, the numeric value of the ones with a long digit is changed. Why is that? How can I make sure all the values do not change?
data output (rename = (ID2 = ID));
set input;
format ID2 32.;
ID2 = ID * 1;
drop ID;
run;
input dataset:
ID (char)
1 4475970392100582373
2 15545765241442042890
3 42747761341861168
dataset:
ID (num)
1 4475970392100582400
2 15545765241442043904
3 42747761341861168 (this one didn't change)
SAS uses 8 bytes of storage to hold numbers so that means it can only hold about 15 digits accurately. The moral of the story is don't convert IDs held as character to numeric as you are likely to lose precision as a consequence. There is no reason to convert numbers stored in character form unless you are performing numerical analysis or mathematical calculations.
Read more about this here: https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&docsetVe...
SAS uses 8 bytes of storage to hold numbers so that means it can only hold about 15 digits accurately. The moral of the story is don't convert IDs held as character to numeric as you are likely to lose precision as a consequence. There is no reason to convert numbers stored in character form unless you are performing numerical analysis or mathematical calculations.
Read more about this here: https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&docsetVe...
I see. The reason why I wanted to convert this variable is I want to use this variable later to do merge. I have 2 datasets have the same variables and I want to merge them by this variable. So, if I keep this variable as character, can I still merge these 2 tables?
Yes, as long as the two variables are both character you can merge them. In fact merging is more reliable leaving them as character.
I see. Thank you so much.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.