Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: Why SAS is storing 0.0999999642 instead of 0.1 in the X?

Options

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

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-15-2012 05:24 AM
(1139 views)

Hello Friends,

I have question regarding the way SAS Stores the Numeric Values. I understood that SAS will store the numeric

values as Floating point numbers.

If the length of the variable is 4 bytes , SAS can store any value less than 2,097,152 correctly without affecting its

precision.

I didnt understood why SAS is storing ? instead of 0.1 in the X Variable(Refer the Program).

Please, I request you to clarify my doubt.

Following is the program , to understand my question clearly.

data test;

length x 4;

X=1/10;

Y=1/10;

run;

data _null_;

set test;

put X=;

put Y=;

run;

Log Output:

x=0.0999999642

y=0.1

Thank you,

John

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Two links adding a bit of flesh to what Ksharp tells you.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695157.htm

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Actually in the computer, you can't store 0.1 exactly .

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Two links adding a bit of flesh to what Ksharp tells you.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695157.htm

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The references are great. Here's another way to look at it. I"m not sure if this helps or not, but just in case it does ...

The "largest number" you picked out as actually the largest integer value that can be stored precisely. There are other numbers, both large and small that can be stored precisely if they fit into the available number of bits. For example, 0.75 can be stored precisely because it takes only two bits to store the value. In a binary system, one bit turned on is 1/2 (or 2**-1), and the next bit turned on is 1/4 (or 2**-2). So 0.75 fits exactly. You can store larger EVEN integers than the "largest integer" because they can drop the "1's" bit and not lose any precision.

Good luck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Your statement "If the length of the variable is 4 bytes , SAS can store any value less than 2,097,152 correctly without affecting its

precision." is wrong.

When thinking about changing the length of a numeric variable, you must consider whether the variable will only contain integers. If so, then changing the length is a legitimate way to save space. However, if there's any chance the variable will contain fractional values, then you should leave the length at 8 bytes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks everybody.

**Don't miss out on SAS Innovate - Register now for the FREE Livestream!**

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

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.