BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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?

Please advice. Thank you.

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

12 REPLIES 12
LinusH
Tourmaline | Level 20

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
senico82_gmail_com
Calcite | Level 5

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

LinusH
Tourmaline | Level 20

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
jakarman
Barite | Level 11

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 --<-----
LinusH
Tourmaline | Level 20

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

Data never sleeps
Murray_Court
Quartz | Level 8

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.

Astounding
PROC Star

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.

LinusH
Tourmaline | Level 20

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
senico82_gmail_com
Calcite | Level 5

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

SASKiwi
PROC Star

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.  

jakarman
Barite | Level 11

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 --<-----

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
  • 12 replies
  • 8019 views
  • 2 likes
  • 6 in conversation