LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 19 Oct 2006 12:29:31 -0700
Reply-To:     David L Cassell <davidlcassell@MSN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         David L Cassell <davidlcassell@MSN.COM>
Subject:      Re: Very Basic Q- Lenghts of a numeric variable
In-Reply-To:  <200610190655.k9IMOrcW016743@malibu.cc.uga.edu>
Content-Type: text/plain; format=flowed

jim2stat@YAHOO.CO.UK replied: > >Hi Raj, > >Next to the other responses a simple example of binary storage of numbers. >Let's limit them to integer numbers in this case. You (should) know a byte >consists of 8 bits. A bit can have the values 0 and 1. So with one bit you >can represent 2 values. With two bits you can represent 4 values (00=0, >01=1, 10=2, 11=3), with three bits 8, with four bits 16, with n bits 2^n >and > thus with 8 bits (one byte) 256 (0-255, the number of different >characters >per byte). So you see here that a value that has a three byte character >representation can be stored binary as one byte. That is what happens and >that is the way to be able to do calculations with the values. > >A value of 8 bytes, or 64 bits, thus could store 2^64 different integer >values. You can calculate the amount yourself, but in character >representation it is a value with many more than 8 characters (bytes). To >enable negative values one bit is used for the sign. > >Another part of the bits of an 8 byte values are (platform dependent how >many) used for the power of 10 to multiply the integer value with. The >power >of 10 may be large positive, representing very large values, where the >rightmost digit is not accurate; adding 1 to such a value does not change >it. And the power of 10 may be negative, representing floating point values >(with decimals behind the decimal point in character notation). > >So, if you define a numeric LENGTH in SAS it concerns the binary storage, >not the character representation. You now can easily see that your number >fits quite well within 8 bytes. As others already pointed out: print is as >a >hex value. Two characters (0-F, 16 values) in hexadecimal representation >occupy one byte (16^2=256), so the number of hexadecimal characters divided >by 2 is the number of bytes hat determine the value. > >I hope this clarifies the principle of binary storage a little bit, byte >[;-) > >Regards - Jim. >-- >Jim Groeneveld, Netherlands >Statistician, SAS consultant >home.hccnet.nl/jim.groeneveld > >On Wed, 18 Oct 2006 14:28:38 -0700, Raj <ramesh.chakri@GMAIL.COM> wrote: > > >data test; > >id = 999999999999999; > >run; > > > >After running this example, the length of the variable in sas shows as > >8. Value in the table as 1E15 > > > >Whats is going on? > > > >I read that sas numeric variable length is 8 .. does it mean it can not > >store a numeric variable of a 10+million value ?? > > > >-Raj.

Jim wrote a very nice reply, but it is also important to realize that your 8 bytes of storage for your number are basically split into what we math-geeks like to call the abscissa and the mantissa. But there won't be a test on that. :-)

When we write a number in scientific notation:

100*pi = 3.1415926E2

we have a part in front that says what the digits look like if we divided out all powers of ten, and a part after the 'E' that tells how many powers of ten we would pull out. So the above is

3.1415926 * 10**2

The 64 bits of storage for your number are then split into the 'precision' part and the 'power of ten' part. So you do not get 64 bits of precision for your number. And the exact number of bits you DO have for the precision is dependent on the operating system. But it's a lot. It's not enough to store 16-digit credit card numbers safely, but it's close.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Try Search Survival Kits: Fix up your home and better handle your cash with Live Search! http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=hmtagline


Back to: Top of message | Previous page | Main SAS-L page