BookmarkSubscribeRSS Feed
zhuxiaoyan1
Quartz | Level 8

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!

13 REPLIES 13
DanielSantos
Barite | Level 11

Hi.

 

What type of conversion you need?

 

SAS numeric variables are 8 byte in length and uses floating representation which has its limits.

 

http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

 

Could you share the code you are running?

 

Daniel Santos @ www.cgd.pt

zhuxiaoyan1
Quartz | Level 8
data want;
set have;
Num_service=input(service_number, 19.);
format Num_service z19.;
run;
DanielSantos
Barite | Level 11

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

zhuxiaoyan1
Quartz | Level 8

yes, It is loading into a database. Thanks!

DanielSantos
Barite | Level 11

OK.

 

Then check if you can bulkload the data into your database. If so, DBSASTYPE is option you are looking for.

 

http://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0v4ma1zb9lu99n172...

 

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

Sven111
Pyrite | Level 9

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.

SASKiwi
PROC Star

Why do you need to convert these to a numeric variable? If you are not doing calculations it shouldn't be necessary.

Sven111
Pyrite | Level 9

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.

zhuxiaoyan1
Quartz | Level 8

It is string variables, but I want convert them into numeric variables. That is what required in our submission file.

Sven111
Pyrite | Level 9

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1474 views
  • 6 likes
  • 5 in conversation