Extracts a substring from an argument
Category: Character
< variable => SUBSTR ( string, position <, length >)
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.
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 .
SAS Statements | Results |
---|---|
----+----1----+----2 | |
date='06MAY98'; month=substr(date,3,3); year=substr(date,6,2); put @1 month @5 year; | MAY 98 |
Functions:
'SUBPAD Function' on page 836
'SUBSTR (left of =) Function' on page 837
'SUBSTRN Function' on page 840