By Ruben Geert van den Berg on May 30, 2014 under SPSS String Functions.

SPSS RTRIM Function

Summary

By default, SPSS right pads string values with spaces up to the length of their containing string variables. You don't usually see this but it may complicate concatenating strings. Such complications are avoided by trimming off trailing spaces using RTRIM (right trim). In Unicode mode, RTRIM is applied automatically but it's fine to use it anyway.

SPSS Rtrim Results of steps 6 and 7 of the example syntax

SPSS Rtrim Example

The syntax below demonstrates two complications that may result from omitting RTRIM. We recommend you run it and inspect the results after each step. Make sure you have no datasets open because they'll prevent SPSS from switching Unicode Mode off.

SPSS Rtrim Syntax Example

*1. Remember settings and switch Unicode mode off.

preserve.

set unicode off.

*2. Create mini dataset.

data list free / first last (2a10).
begin data
John Doe
end data.

*3. Declare new string variable.

string full(a10).

*4. Attempt 1. Concat does not seem to work.

compute full = concat(first,last).
exe.

*5. Increase string length.

alter type full(a20).

*6. Attempt 2. Results in excessive spaces.

compute full = concat(first,last).
exe.

*7. Attempt 3. Rtrim removes excessive spaces.

compute full = concat(rtrim(first),' ',rtrim(last)).
exe.

*9. Close all open data.

dataset close all.

new file.

*10. Restore system settings.

restore.

SPSS Rtrim Syntax Notes

Comment on this Tutorial

*Required field. Your comment will show up after approval from a moderator.