Returns the length of a non-blank character string, excluding trailing blanks, and returns 1 for a blank character string
Category: Character
LENGTH ( string )
string
specifies a character constant, variable, or expression.
The LENGTH function returns an integer that represents the position of the rightmost non-blank character in string . If the value of string is blank or missing, LENGTH returns a value of 1. If string is a numeric variable (either initialized or uninitialized ), LENGTH returns a value of 12 and prints a note in the SAS log that the numeric values have been converted to character values.
The LENGTH and LENGTHN functions return the same value for non-blank character strings. LENGTH returns a value of 1 for blank character strings, whereas LENGTHN returns a value of 0.
The LENGTH function returns the length of a character string, excluding trailing blanks, whereas the LENGTHC function returns the length of a character string, including trailing blanks. LENGTH always returns a value that is less than or equal to the value returned by LENGTHC.
The LENGTH function returns the length of a character string, excluding trailing blanks, whereas the LENGTHM function returns the amount of memory in bytes that is allocated for a character string. LENGTH always returns a value that is less than or equal to the value returned by LENGTHM.
SAS Statements | Results |
---|---|
len=length('ABCDEF'); put len; | 6 |
len2=length(' '); put len2; | 1 |
Functions:
'LENGTHC Function' on page 628
'LENGTHM Function' on page 629
'LENGTHN Function' on page 631