LENGTH Function


Returns the length of a non-blank character string, excluding trailing blanks, and returns 1 for a blank character string

Category: Character

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 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.

Comparisons

  • 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.

Examples

SAS Statements

Results

  len=length('ABCDEF');   put len;  
  6  
  len2=length(' ');   put len2;  
  1  

See Also

Functions:

  • 'LENGTHC Function' on page 628

  • 'LENGTHM Function' on page 629

  • 'LENGTHN Function' on page 631




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net