## SAS auto round figure if more that 18 digit

Solved
Occasional Contributor
Posts: 9

# SAS auto round figure if more that 18 digit

Hi,

We notice SAS base will round the figure is more than 18 digit.

Is there any setting in server/client machine if we want to programme to show exact value?

Below is the sample code:

data test;

format b best32.;

format d best32.;

format f best32.;

x = '0010000000130000123';

y = '001000000013000012';

z = '00100000001300001';

len1 = length(x);

len2 = length(y);

len3 = length(z);

b = input(x, best32.);

d = input(y, best32.);

f = input(z, best32.);

run;

Regards,

Senico

Accepted Solutions
Solution
‎08-20-2013 10:08 AM
Super User
Posts: 6,761

## Re: SAS auto round figure if more that 18 digit

Jaap Karman gave you the right reference material.  Let me give you the short answer.

No, it's not possible.  The way that SAS stores numeric values, it has room to store only 15 to 16 significant digits (ASCII vs. EBCDIC).  If you want an accurate representation of longer values, you will have to print the character variable instead.

There are exceptions.  If you experiment with numbers that are multiple of 8, for example, you will see that you can store more significant digits.  However, understanding why requires reading up on the reference material that you'll find in Jaap's link.

Good luck.

All Replies
Super User
Posts: 5,876

## Re: SAS auto round figure if more that 18 digit

I'n not following you. What do mean by round?

What your example shows is that leading zeros is not displayed by default.

If you want leading zeros on numerical variable, use Zn. format.

Data never sleeps
Occasional Contributor
Posts: 9

## Re: SAS auto round figure if more that 18 digit

Hi,

Let me provide you simple example:

data test;

format b best32.;

x = '0010000000130000123';

len1 = length(x);

b = input(x, best32.);

run;

output from test datasets:

x = 10000000130000123

b = 10000000130000124

Expected output:

x = 10000000130000123

b = 10000000130000123

My question is why value from column 'b' has been round?

I am expecting that column 'x' and column 'b' having the same value.

Senico

Super User
Posts: 5,876

## Re: SAS auto round figure if more that 18 digit

For starters, X i char and B in numeric, which in most situation isn't comparable.

And you need to understand how SAS stores numerical values, and displaying them.

Leading zeros doesn't really hold any information, nor influence any calculation. Therefore, they are not displayed by default.

Use Zn. format (haven't I already said that?).

Data never sleeps
Posts: 3,215

## Re: SAS auto round figure if more that 18 digit

Linus, Not only starters have problems to understand how SAS works wiht numbers,,, uh it is IEE that applies everywhere..

Many more have people are having problems understanding working with numbers ... floating-flops.

Some background of how using a slider would be convenient.

---->-- ja karman --<-----
Super User
Posts: 5,876

## Re: SAS auto round figure if more that 18 digit

I also need to file a complaint to my laser surgery practice, I just saw the rounding "error"... :smileyblush:

Data never sleeps
Contributor
Posts: 45

## Re: SAS auto round figure if more that 18 digit

I dont beleive that there is a solution to this problem in the SAS environment.

The default length of a numeric variable is 8 bytes, this is also the maximum length. The largest integer that can be expressed exactly in SAS is 9,007,199,254,740,992.

I notice that your example numbers have leading zeroes, and these supposed to be codes of some kind? You might want to consider storing them as character varaibles where they can be stored exactly.

Posts: 3,215

## Re: SAS auto round figure if more that 18 digit

same as:

https://communities.sas.com/message/178091#178091

---->-- ja karman --<-----
Solution
‎08-20-2013 10:08 AM
Super User
Posts: 6,761

## Re: SAS auto round figure if more that 18 digit

Jaap Karman gave you the right reference material.  Let me give you the short answer.

No, it's not possible.  The way that SAS stores numeric values, it has room to store only 15 to 16 significant digits (ASCII vs. EBCDIC).  If you want an accurate representation of longer values, you will have to print the character variable instead.

There are exceptions.  If you experiment with numbers that are multiple of 8, for example, you will see that you can store more significant digits.  However, understanding why requires reading up on the reference material that you'll find in Jaap's link.

Good luck.

Super User
Posts: 5,876

## Re: SAS auto round figure if more that 18 digit

The magic question here is how Senico wish to use these large numbers?

Is it just exploration of SAS limitations, or a real life problem?

Data never sleeps
Occasional Contributor
Posts: 9

## Re: SAS auto round figure if more that 18 digit

Hi,

This is real life problem.

I need to transform the example from character column to numeric column

and use it as account_number:

0010000000130000123    ->  10000000130000123

Senico

Super User
Posts: 3,917

## Re: SAS auto round figure if more that 18 digit

It is common practice across most industries that use account numbers to store them as character columns - for example banking.

I am curious to know why you want to transform them into numeric columns.

Posts: 3,215

## Re: SAS auto round figure if more that 18 digit

As it is indeed making no sense to try calculating the mean or skewness on accountnumbers... A correlation with the GPS y location?

The best approach would be tot treat it as char. It are characters within the 0-9 range (constraint).

One exception, bankers are having problems with numbers. The IBAN number? (of course no number as it contains A-Z.

But the made a convention with mod 97 calculation wiht 2 checking chars on it.  As the resolution in the number is a common problem this calculation has been split up in several parts in the example. International Bank Account Number - Wikipedia, the free encyclopedia

---->-- ja karman --<-----
🔒 This topic is solved and locked.