TRIM Function


Removes trailing blanks from character expressions and returns one blank if the expression is missing

Category: Character

Syntax

TRIM ( argument )

Arguments

argument

  • specifies any SAS character expression.

Details

If the TRIM 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.

TRIM copies a character argument, removes all trailing blanks, and returns the trimmed argument as a result. If the argument is blank, TRIM returns one blank. TRIM is useful for concatenating because concatenation does not remove trailing blanks.

Assigning the results of TRIM to a variable does not affect the length of the receiving variable. If the trimmed value is shorter than the length of the receiving variable, SAS pads the value with new blanks as it assigns it to the variable.

Comparisons

The TRIM and TRIMN functions are similar. TRIM returns one blank for a blank string. TRIMN returns a null string (zero blanks) for a blank string.

Examples

Example 1: Removing Trailing Blanks

These statements and this data line produce these results:

 data test;     input part1 $ 1-10 part2 $ 11-20;     hasblank=part1part2;     noblank=trim(part1)part2;     put hasblank;     put noblank;     datalines; 

Data Line

Results

 

----+----1----+----2

apple sauce

apple sauce

 

applesauce

Example 2: Concatenating a Blank Character Expression

SAS Statements

Results

x="A"trim(" ")"B"; put x;

A B

x=" "; y=" > "trim(x)" < "; put y;

> <

See Also

Functions:

  • 'COMPRESS Function' on page 458

  • 'LEFT Function' on page 626

  • 'RIGHT Function' on page 787




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net