BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cosmid
Lapis Lazuli | Level 10

Hi,

 

For numeric, the default is 8 bytes.

 

Question 1.: What is the range? When I google this, I see some place say it's 2-8 and some place say it's 3-8?

 

Question 2: What happens when you need a numeric var to store more than 8 bytes?

 

For character, the range is 1 to 32,767 bytes.

 

Question 3: The default size for character var is also 8 bytes?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The minimum length you can use to store a numeric variable varies based on the hardware being used.  If you are using an IBM mainframe then you can store only 2 bytes.  But if you are using other hardware you must store at least 3 bytes.  This is because of differences between the floating point representations used by the two.

 

You cannot store numbers using more than 8 bytes.  SAS uses 64 bit floating point numbers.  It only take 8 bytes to store 64 bits.  This also means there is a limit on the maximum number of digits of precision that you can store.

 

If you do not DEFINE the storage length for your variables then SAS is forced to GUESS what length to use.  It does this based on the information that is available at the point when it must define the length.  For example if the first place you reference a character variable is in an assignment statement it will set the length to match the length of the value being assigned. If the first place it is referenced is when it is associated with a format or an informat then it will set the length based on the width of the format or informat being used. If there is no other clue about how to define the length it will use 8.  For example if the first place the variable SEX appears is in the input statement:

input id sex $ ;

SAS will decide that SEX should be character because of the $ modifier on the INPUT statement.  But since there is no column numbers or informat specified that could help if guess how long to make it then it will just make it a length of 8.

 

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

The minimum length you can use to store a numeric variable varies based on the hardware being used.  If you are using an IBM mainframe then you can store only 2 bytes.  But if you are using other hardware you must store at least 3 bytes.  This is because of differences between the floating point representations used by the two.

 

You cannot store numbers using more than 8 bytes.  SAS uses 64 bit floating point numbers.  It only take 8 bytes to store 64 bits.  This also means there is a limit on the maximum number of digits of precision that you can store.

 

If you do not DEFINE the storage length for your variables then SAS is forced to GUESS what length to use.  It does this based on the information that is available at the point when it must define the length.  For example if the first place you reference a character variable is in an assignment statement it will set the length to match the length of the value being assigned. If the first place it is referenced is when it is associated with a format or an informat then it will set the length based on the width of the format or informat being used. If there is no other clue about how to define the length it will use 8.  For example if the first place the variable SEX appears is in the input statement:

input id sex $ ;

SAS will decide that SEX should be character because of the $ modifier on the INPUT statement.  But since there is no column numbers or informat specified that could help if guess how long to make it then it will just make it a length of 8.

 

 

cosmid
Lapis Lazuli | Level 10
Thank you!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1249 views
  • 2 likes
  • 2 in conversation