Previous Page | Next Page

The SQL Procedure

BTRIM function


Removes blanks or specified characters from the beginning, the end, or both the beginning and end of a character string.
BTRIM (<<btrim-specification> <'btrim-character' FROM>> sql-expression)

Arguments

btrim-specification

is one of the following:

LEADING

removes the blanks or specified characters from the beginning of the character string.

TRAILING

removes the blanks or specified characters from the end of the character string.

BOTH

removes the blanks or specified characters from both the beginning and the end of the character string.

Default: BOTH
btrim-character

is a single character that is to be removed from the character string. The default character is a blank.

sql-expression

must resolve to a character string or character variable and is described in sql-expression.


Details

The BTRIM function operates on character strings. BTRIM removes one or more instances of a single character (the value of btrim-character) from the beginning, the end, or both the beginning and end of a string, depending whether LEADING, TRAILING, or BOTH is specified. If btrim-specification is not specified, then BOTH is used. If btrim-character is omitted, then blanks are removed.

Note:   SAS adds trailing blanks to character values that are shorter than the length of the variable. Suppose you have a character variable Z, with length 10, and a value xxabcxx . SAS stores the value with three blanks after the last x (for a total length of 10). If you attempt to remove all the x characters with

btrim(both 'x' from z)

then the result is abcxx because PROC SQL sees the trailing characters as blanks, not the x character. In order to remove all the x characters, use

btrim(both 'x' from btrim(z))

The inner BTRIM function removes the trailing blanks before passing the value to the outer BTRIM function.  [cautionend]

Previous Page | Next Page | Top of Page