Returns a character string with all leading and trailing blanks removed
Category: Character
STRIP ( string )
string
is a character constant, variable, or expression.
If the STRIP 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 STRIP function returns the argument with all leading and trailing blanks removed. If the argument is blank, STRIP returns a string with a length of zero.
Assigning the results of STRIP to a variable does not affect the length of the receiving variable. If the value that is trimmed is shorter than the length of the receiving variable, SAS pads the value with new trailing blanks.
Note: The STRIP function is useful for concatenation because the concatenation operator does not remove trailing blanks.
The following list compares the STRIP function with the TRIM and TRIMN functions:
For strings that are blank, the STRIP and TRIMN functions return a string with a length of zero, whereas the TRIM function returns a single blank.
For strings that lack leading blanks, the STRIP and TRIMN functions return the same value.
For strings that lack leading blanks but have at least one non-blank character, the STRIP and TRIM functions return the same value.
Note: STRIP( string ) returns the same result as TRIMN(LEFT( string )) , but the STRIP function runs faster.
The following example shows the results of using the STRIP function to delete leading and trailing blanks.
options pageno=1 nodate ls=80 ps=60; data lengthn; input string $char8.; original = '*' string '*'; stripped = '*' strip(string) '*'; datalines; abcd abcd abcd abcdefgh x y z ; proc print data=lengthn; run;
The SAS System 1 Obs string original stripped 1 abcd *abcd * *abcd* 2 abcd * abcd * *abcd* 3 abcd * abcd * *abcd* 4 abcdefgh *abcdefgh* *abcdefgh* 5 xyz * x y z * *xyz*
Functions:
'CAT Function' on page 411
'CATS Function' on page 412
'CATT Function' on page 414
'CATX Function' on page 416
'LEFT Function' on page 626
'TRIM Function' on page 862
'TRIMN Function' on page 864