BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
newboy1218
Quartz | Level 8

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)

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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...

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

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...

newboy1218
Quartz | Level 8

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?

SASKiwi
PROC Star

Yes, as long as the two variables are both character you can merge them. In fact merging is more reliable leaving them as character.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1454 views
  • 1 like
  • 2 in conversation