Previous Page | Next Page

Functions and CALL Routines

LENGTH Function



Returns the length of a non-blank character string, excluding trailing blanks, and returns 1 for a blank character string.
Category: Character
Restriction: I18N Level 0
Tip: DBCS equivalent function is KLENGTH in SAS National Language Support (NLS): Reference Guide.
Tip: The LENGTH function returns a length in bytes, while the KLENGTH function returns a length in a character based unit.

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

LENGTH(string)


Arguments

string

specifies a character constant, variable, or expression.


Details

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, LENGTH returns a value of 1. If string is a numeric constant, variable, or expression (either initialized or uninitialized), SAS automatically converts the numeric value to a right-justified character string by using the BEST12. format. In this case, LENGTH returns a value of 12 and writes a note in the SAS log stating that the numeric values have been converted to character values.


Comparisons


Examples

SAS Statements Results
len=length('ABCDEF');
put len;


len2=length(' ');
put len2;
 
6


 
1


See Also

Functions:

LENGTHC Function

LENGTHM Function

LENGTHN Function

Previous Page | Next Page | Top of Page