turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- SAS auto round figure if more that 18 digit

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-20-2013 04:04 AM

`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

Accepted Solutions

Solution

08-20-2013
10:08 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 10:08 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 05:07 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LinusH

08-20-2013 05:21 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 06:32 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LinusH

08-20-2013 07:02 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jakarman

08-20-2013 08:34 AM

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

Data never sleeps

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 05:21 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 05:47 AM

Solution

08-20-2013
10:08 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 10:08 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Astounding

08-20-2013 10:38 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LinusH

08-20-2013 09:22 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to senico82_gmail_com

08-20-2013 10:57 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASKiwi

08-21-2013 12:43 AM

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