DATA Step, Macro, Functions and more

length of numeric variables in SAS under windows

Reply
Contributor
Posts: 65

length of numeric variables in SAS under windows

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!

Super Contributor
Posts: 474

Re: length of numeric variables in SAS under windows

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

Contributor
Posts: 65

Re: length of numeric variables in SAS under windows

data want;
set have;
Num_service=input(service_number, 19.);
format Num_service z19.;
run;
Super Contributor
Posts: 474

Re: length of numeric variables in SAS under windows

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

Contributor
Posts: 65

Re: length of numeric variables in SAS under windows

yes, It is loading into a database. Thanks!

Super Contributor
Posts: 474

Re: length of numeric variables in SAS under windows

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

Frequent Contributor
Posts: 82

Re: length of numeric variables in SAS under windows

[ Edited ]

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.

Contributor
Posts: 65

Re: length of numeric variables in SAS under windows

Thanks!

Super User
Posts: 3,106

Re: length of numeric variables in SAS under windows

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

Super User
Posts: 6,938

Re: length of numeric variables in SAS under windows

Are these numbers after all? The leading zeroes make me think that these are actually key strings consisting of digits only.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 82

Re: length of numeric variables in SAS under windows

[ Edited ]

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.

Contributor
Posts: 65

Re: length of numeric variables in SAS under windows

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

Frequent Contributor
Posts: 82

Re: length of numeric variables in SAS under windows

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.

Super User
Posts: 6,938

Re: length of numeric variables in SAS under windows

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 13 replies
  • 304 views
  • 6 likes
  • 5 in conversation