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

I just want to confirm that in length statement, when you define the length as "$10" 

 

Is it means that this cell can only contain a word/phrase less than 10 characters?

 

Is one character use 1 byte?

 

Thanks!  

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@zimu94681 wrote:

I just want to confirm that in length statement, when you define the length as "$10" 

 

Is it means that this cell can only contain a word/phrase less than 10 characters?

 

Is one character use 1 byte?

 

Thanks!  


The length is the number of BYTES that are stored in the dataset.  For character variables that is also the number of bytes they can contain in the processing of the data step.  For numeric variables they always need 8 bytes but the LENGTH can be used to control how many bytes are written to the dataset. On Windows/Linux this can be between 3 and 8 bytes. Z/OS you can also store numbers in just 2 bytes.

 

The number of characters that will fit in a fixed number of bytes depends on what encoding your SAS session is using. If you are using a single byte encoding, like WLATIN1, then each character takes one byte.  If you are using double byte characters (common with Japanese or Chinese) then each character needs two bytes.   If you are using UTF8 encoding (also called unicode support) then a character can use between 1 and 3 bytes, depending on the character.

View solution in original post

2 REPLIES 2
Reeza
Super User

length

refers to the number of bytes used to store each of the variable's values in aSAS data set. You can use aLENGTH statementto set the length of both numeric and character variables. Variable lengths that are specified in a LENGTH statement affect the length of numeric variables only in the output data set. During processing, all numeric variables have a length of 8. Lengths of character variables that are specified in a LENGTH statement affect both the length during processing and the length in the output data set.

Source:

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n08fs0rt7fikeln1uh0t8v5pt25d.htm&docsetVe...

 

Yes, a length of 10 means you can store character values that are a length of 10 or less only and that's 10 bytes.

 


@zimu94681 wrote:

I just want to confirm that in length statement, when you define the length as "$10" 

 

Is it means that this cell can only contain a word/phrase less than 10 characters?

 

Is one character use 1 byte?

 

Thanks!  


 

 

 

Tom
Super User Tom
Super User

@zimu94681 wrote:

I just want to confirm that in length statement, when you define the length as "$10" 

 

Is it means that this cell can only contain a word/phrase less than 10 characters?

 

Is one character use 1 byte?

 

Thanks!  


The length is the number of BYTES that are stored in the dataset.  For character variables that is also the number of bytes they can contain in the processing of the data step.  For numeric variables they always need 8 bytes but the LENGTH can be used to control how many bytes are written to the dataset. On Windows/Linux this can be between 3 and 8 bytes. Z/OS you can also store numbers in just 2 bytes.

 

The number of characters that will fit in a fixed number of bytes depends on what encoding your SAS session is using. If you are using a single byte encoding, like WLATIN1, then each character takes one byte.  If you are using double byte characters (common with Japanese or Chinese) then each character needs two bytes.   If you are using UTF8 encoding (also called unicode support) then a character can use between 1 and 3 bytes, depending on the character.

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
  • 2 replies
  • 4277 views
  • 4 likes
  • 3 in conversation