Previous Page | Next Page

Functions and CALL Routines

STRIP Function



Returns a character string with all leading and trailing blanks removed.
Category: Character
Restriction: I18N Level 0

Syntax
Arguments
Details
Length of Returned Variable
The Basics
Comparisons
Examples
See Also

Syntax

STRIP(string)

Arguments

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.   [cautionend]


Comparisons

The following list compares the STRIP function with the TRIM and TRIMN functions:

Note:    STRIP(string) returns the same result as TRIMN(LEFT(string)) , but the STRIP function runs faster.   [cautionend]


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

Functions:

CAT Function

CATS Function

CATT Function

CATX Function

LEFT Function

TRIM Function

TRIMN Function

Previous Page | Next Page | Top of Page