Previous Page | Next Page

Functions and CALL Routines

SUBSTR (right of =) Function



Extracts a substring from an argument.
Category: Character
Restriction: I18N Level 0
Tip: DBCS equivalent functions are KSUBSTR and KSUBSTRB in SAS National Language Support (NLS): Reference Guide.

Syntax
Arguments
Details
Examples
See Also

Syntax

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


Arguments

variable

specifies a valid SAS variable name.

string

specifies a character constant, variable, or expression.

position

specifies a numeric constant, variable, or expression that is the beginning character position.

length

specifies a numeric constant, variable, or 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

In a DATA step, if the SUBSTR (right of =) function returns a value to a variable that has not previously been assigned a length, then that variable is given 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

SUBSTR (left of =) Function

SUBSTRN Function

Previous Page | Next Page | Top of Page