Desktop productivity for business analysts and programmers

Import of long numbers

Reply
Occasional Contributor
Posts: 13

Import of long numbers

Hello!

One of the variables in my source of data is number of 16 characters.
I want this variable to have a numeric format in my dataset.
When I import data into SAS, using EG import wizard, I choose numeric format, but only 12 characters appear with trimming 4 last numbers.

Can anybody explain how to import long numbers in SAS.
Super Contributor
Super Contributor
Posts: 365

Re: Import of long numbers

Hello V. Andy,

I tried to import text file contating long number with EG 4.3 import wizard. It was successful but I have to change Source Informat, Output Format and Output Format to BEST20.

Sincerely,
SPR
Trusted Advisor
Posts: 1,056

Re: Import of long numbers

Be careful with numbers with large numbers of digits; 15 significant digits is the most that will be accurately retained on most processors today. 16 digit and larger numbers risk losing accuracy.

Tom
Respected Advisor
Posts: 3,831

Re: Import of long numbers

Hi

If you don't need these digits for calculations then better store it in a character variable. Else you're going to have precision problems.

HTH
Patrick
Occasional Contributor
Posts: 13

Re: Import of long numbers

Thanks to everybody for help!

I just wanted to increcase the database productivity and decrease space occupied by dataset. I thought I could do it keeping my field in numeric format rather than in character.
Respected Advisor
Posts: 3,063

Re: Import of long numbers

I'm with TomKari and Patrick on this one. If you have ever dealt with bank data, account numbers and credit card numbers are typically up to 16 digits long and so are always stored as character to avoid precision issues.
Valued Guide
Posts: 2,174

Re: Import of long numbers

I find all releases of SAS can support 16digit numbers in numeric variables. Unfortunately, the default behaviour of excel is to convert the 16th (on th eright) to zero!
Unsigned packed decimal (format/informat PK.) saves half the storage over strings.
have a look at the saslog after running this code, as tested on AIX
data;
input a : best20. ;
file "&sysuserid/test.hex.data" ;
put a pk8. ;
list;cards;
1234567812345678
-3456
0
88888888888888888
;
data ;
infile "&sysuserid/test.hex.data" ;
input @;
list ;
run;
Trusted Advisor
Posts: 1,056

Re: Import of long numbers

Yes, SOME 16 digit numbers will be represented correctly, but large numbers will fail. In windows, the following code

data work.digit_test;
a = 9234567812345670; put a 16.;
a = 9234567812345671; put a 16.;
a = 9234567812345672; put a 16.;
a = 9234567812345673; put a 16.;
a = 9234567812345674; put a 16.;
a = 9234567812345675; put a 16.;
a = 9234567812345676; put a 16.;
a = 9234567812345677; put a 16.;
a = 9234567812345678; put a 16.;
a = 9234567812345679; put a 16.;
run;

produces this log.

9234567812345670
9234567812345672
9234567812345672
9234567812345672
9234567812345674
9234567812345676
9234567812345676
9234567812345676
9234567812345678
9234567812345680

According to the SAS Unix notes, the code should fail in your environment as well. Give it a try, and post back what happens.

Tom
Valued Guide
Posts: 2,174

Re: Import of long numbers

Tom is correct, of course.
On windows and Unix not all 16 digit numbers can be presented accurately. The rule is about size. (and notice that in Tom's examples, even numbers seem OK)

The SAS Companions for SAS on Windows and Unix, show that the highest integer up to which integers are presented reliably, is 9,007,199,254,740,992.
In "SAS 9.2 Companion for Windows, Second Edition", see http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/numvar.htm#maxint

On the zOS platform the limit is higher at 72,057,594,037,927,936
So, on zOS platform there shouild be no problem holding and using a 16 digit number.

peterC just to add that results from Toms data step are the same when run in unix (aix-64) Message was edited by: Peter.C
Ask a Question
Discussion stats
  • 8 replies
  • 4045 views
  • 0 likes
  • 6 in conversation