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

Hi, 

 

I'm confused with the numerical variable's width and its maximum value?

 

- The following is from the book: 3 bytes -> 8192, 4 bytes -> 2097152 ...

jz127323_0-1632263421079.png

- But in my understanding, the maximum values are: 3 bytes -> 2 ** 24 -1 = 16,777,215, 4 bytes -> 4,294,967,295 ...

 

So, I don't understand the logic in  SAS's bytes in variable definition?

 

thanks

James

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

First, 8,192 is the maximum CONSECUTIVE integer that SAS will store as a 3-byte field.  But that storage format will also hold larger values, for instance

  1. every even number from 8,192 to 2*8,192
  2. every 0mod4 number from 2*8,192 to 4*8,192
  3. etc.

BTW, it would also hold

  1. every integer from 8,192 down to 4,096,
  2. then every half  (i.e. 0mod(0.5) from 4,096 down to 2,048
  3. etc.

 

Secondly, your use of the 24 bits is thinking in terms of integer storage, but SAS uses a floating point storage format, reserving

  1. 1 bit for sign
  2. 11 bits for exponent
  3. 12 bits (=24 - 1 - 11) for mantissa   (which would be 52 bits using the default 8-byte numeric storage).

For a 12 bit mantissa, the largest consecutive integer storable would be 2**13 (=8,192).

 

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

SAS stores numbers as 64 bit floating point numbers.  Think of scientific notation (3.5E13) only using base 2 instead of base 10.

 

So part of those 64 bits are reserved for storing the magnitude.  When you restrict the storage to just 3 of the 8 bytes you do NOT have 3*8 = 24 bits left for storing the actual number.

 

2**13 = 8,192 so 11 of the 24 bits are used to store the magnitude.

 

 

jz127323
Obsidian | Level 7

Thanks a lot!

mkeintz
PROC Star

First, 8,192 is the maximum CONSECUTIVE integer that SAS will store as a 3-byte field.  But that storage format will also hold larger values, for instance

  1. every even number from 8,192 to 2*8,192
  2. every 0mod4 number from 2*8,192 to 4*8,192
  3. etc.

BTW, it would also hold

  1. every integer from 8,192 down to 4,096,
  2. then every half  (i.e. 0mod(0.5) from 4,096 down to 2,048
  3. etc.

 

Secondly, your use of the 24 bits is thinking in terms of integer storage, but SAS uses a floating point storage format, reserving

  1. 1 bit for sign
  2. 11 bits for exponent
  3. 12 bits (=24 - 1 - 11) for mantissa   (which would be 52 bits using the default 8-byte numeric storage).

For a 12 bit mantissa, the largest consecutive integer storable would be 2**13 (=8,192).

 

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 650 views
  • 4 likes
  • 3 in conversation