BookmarkSubscribeRSS Feed
StickyRoll
Fluorite | Level 6

I am new to SAS Programming. Recently my laptop has been formatted and I am still waiting for my IT Team to give me a new  SAS installation. Since I have no access to SAS environment, I have a question here.

 

Assuming the source (load from csv) has numeric column that has numeric with 32 length and 8 decimal places. For example:

123,456,789,012,345,678,901,234,567,890,12.99995555

 

I want to store the column as numeric because it will be used as a calculation in the next step. Understand that SAS numeric will only supports 8 bytes which translate to max 15 numeric length. Will it work if the numeric length remained 8 bytes but format it as BEST32.8?

 

I hope i learn something here. Appreciate your effort in explaining. 

6 REPLIES 6
FreelanceReinh
Jade | Level 19

Hello @StickyRoll and welcome to the SAS Support Communities!

 

No, this won't work. Once you've lost the 40-digits precision by storing the value in an 8-byte numeric variable (typically resulting in a precision of 15-16 decimal digits) there is no way to recover it from that variable. Formats just control how a value is displayed. Also note that the BEST32.8 format (edit: which is actually the BEST32. format) has a total length of 32 characters including the decimal places, the decimal point, a minus sign (if any) and exponential notation (if needed). To avoid loss of information you will need to store the number in a character variable (of sufficient length) and use advanced techniques to perform the "calculation in the next step."

 

Addendum:


@StickyRoll wrote:

For example:

123,456,789,012,345,678,901,234,567,890,12.99995555 


The binary floating-point representation of this number would require (at least) 129 mantissa bits in order to achieve sufficient precision, but only 52 are available in an 8-byte numeric variable under Windows and Unix (see Numerical Accuracy in SAS Software).

ChrisNZ
Tourmaline | Level 20

> Will it work if the numeric length remained 8 bytes

To add a brick to the building of knowledge provided by @FreelanceReinh , it depends on what you mean by "work"

SAS can store numbers up to 1e308, like any 8-byte-storing program on PC/Unix platforms (mainframes are different).

So yes it will work and you can perform calculations, but precision will be lost. Only the first 15 digits will be exact. 

SASKiwi
PROC Star

What real world metric does this represent? The number of stars in the universe? The number of atoms that make up the Earth? Total USA debt? 😉

StickyRoll
Fluorite | Level 6

Hi everyone,

 

If i understand correctly, SAS Numeric can only store the precision up to 15 digits. 

For example:

123,456,789,012.987

123,456,789,0.98765

123,456,78.9876543

 

The type is best32..

Kurt_Bremser
Super User

The type can only be character or numeric.

The length of a numeric variable can be between 3 and 8 (on z/OS mainframes 2 and 😎

The format determines how the value is displayed, it does not have an influence on the precision or the minimum/maximum value that can be stored.

 

And yes, with 8 bytes floating point a maximum of 15 decimal digits can be represented reliably. And, when working with decimal fractions, you will quickly find out that there are a lot of them that result in periodic numbers (infinite number of binary digits) when represented as binary, so you will always have rounding errors there.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1523 views
  • 4 likes
  • 5 in conversation