Chapter Contents

Previous

Next
LENGTH

LENGTH



Returns the length of a trimmed character string

Category: Character


Syntax
Details
Examples
Example 1: Using the LENGTH Function
Example 2: Using the LENGTH Function with NOTRIM
See Also

Syntax

length=LENGTH(cval,<'NOTRIM'>);

length
contains the length of the trimmed character string.

Type: Numeric

cval
is the character value whose length is to be determined.

Type: Character

'NOTRIM'
specifies that trailing blanks should be counted as part of the string length.

Type: Character


Details

The resulting value is the position of the right-most nonblank character in the specified string cval.

When NOTRIM is specified, LENGTH returns the length of a string, including trailing blanks.

By default, variables automatically remove leading blanks when values are assigned to them. The $CHAR format and informat must be assigned to a variable in order for leading blanks to be considered in determining the length of a variable.


Examples

Example 1: Using the LENGTH Function

Return the length of the character variable S:

length s $ 5;
s='ab ';
l=length(s);
put 'L='l;
This program produces the following output:
L=2

Example 2: Using the LENGTH Function with NOTRIM

Return the length of the character variable S, using the NOTRIM option:

s = 'xy  ';
l = length(s, 'notrim');
put 'L='l;
This program produces the following output:
L=4

See Also

MLENGTH


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.