SUBSTR (right of) Function


SUBSTR (right of =) Function

Extracts a substring from an argument

Category: Character

Syntax

< variable => SUBSTR ( string, position <, length >)

Arguments

variable

  • specifies a valid SAS variable name .

string

  • specifies any SAS character expression.

position

  • specifies a numeric expression that is the beginning character position.

length

  • specifies a numeric expression that is the length of the substring to extract.

  • Interaction: If length is zero, a negative value, or larger than the length of the expression that remains in string after position , SAS extracts the remainder of the expression. SAS also sets _ERROR_ to 1 and prints a note to the log indicating that the length argument is invalid.

  • Tip: If you omit length , SAS extracts the remainder of the expression.

Details

If the SUBSTR function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the length of the first argument.

The SUBSTR function returns a portion of an expression that you specify in string . The portion begins with the character that you specify by position , and is the number of characters that you specify in length .

Examples

SAS Statements

Results

 

----+----1----+----2

  date='06MAY98';   month=substr(date,3,3);   year=substr(date,6,2);   put @1 month @5 year;  
  MAY 98  

See Also

Functions:

  • 'SUBPAD Function' on page 836

  • 'SUBSTR (left of =) Function' on page 837

  • 'SUBSTRN Function' on page 840




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