Functions and CALL Routines |
Category: | Character |
Restriction: | I18N Level 0 |
Syntax | |
Arguments | |
Details | |
Length of Returned Variable | |
The Basics | |
Comparisons | |
Examples | |
See Also |
Syntax |
STRIP(string) |
Details |
In a DATA step, if the STRIP function returns a value to a variable that has not previously been assigned a length, then that variable is given the length of the 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 leading or trailing blanks.
Comparisons |
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.
Examples |
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;
Results from the STRIP Function
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 x y z * x y z * *x y z*
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.