I'm trying to convert a char var into numeric var, but the I got something different from waht in the char var.
char_var num_var
0080082362016000002 0080082362016000000
0080082362016000003 0080082362016000000
0114419572016000028 0114419572016000032
The length of the var causes the problem. SAS can only represent 16 digits exactly under windows. Is there any way to overcome this? Thanks!
Hi.
What type of conversion you need?
SAS numeric variables are 8 byte in length and uses floating representation which has its limits.
Could you share the code you are running?
Daniel Santos @ www.cgd.pt
Hi.
What everyone said previously. It's not possible in plain SAS.
But then, why does this have to be numeric?
Is it for loading into a Database? If so you may typecast it at load and it won't be a problem.
Daniel Santos @ www.cgd.pt
yes, It is loading into a database. Thanks!
OK.
Then check if you can bulkload the data into your database. If so, DBSASTYPE is option you are looking for.
It will type cast the column while loading into the database.
That way, there is no need to convert the character variable into numeric, SAS will do that for you during loading.
Hope it helps.
Daniel Santos @ www.cgd.pt
Not easily, not that I'm aware of anyways. Here's an article that discusses various options for bignum handling. When I've needed to use larger numbers I usually offload it to a database like Oracle or Teradata and then do explicit pass-through PROC SQL to handle it.
Thanks!
Why do you need to convert these to a numeric variable? If you are not doing calculations it shouldn't be necessary.
Are these numbers after all? The leading zeroes make me think that these are actually key strings consisting of digits only.
I was thinking this as well, or even some oddly formatted date/timestamp string (possibly concatenated with another string/value) given that all three examples have 2016 in there.
It is string variables, but I want convert them into numeric variables. That is what required in our submission file.
Submission file to what? If you're submitting the final output to something outside of SAS anyways (CSV, etc.) then it shouldn't matter how SAS treats it internally as long as you don't need to do numeric manipulation on that variable.
In pure SAS, numbers like that can't be handled. Technically impossible. Only in proc ds2 you have other number formats at your disposal, or in database systems.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.