STRIP Function

Returns a character string with all leading and trailing blanks removed.

Category: Character
Restriction: I18N Level 0 functions are designed for use with Single Byte Character Sets (SBCS) only.

Syntax

STRIP(string)

Required Argument

string

is a character constant, variable, or expression.

Details

Length of Returned Variable

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 Basics

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.

Example

The following example shows the results of using the STRIP function to delete leading and trailing blanks.
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
Results from the STRIP Function