The TRIM function is used to remove trailing spaces from character values. It is usually used when concatenating variables.
Example

The data set above contains 2 columns: VAR1 and VAR2.
Both variables have a length of 10:
Both variables have a length of 10:


You can create the data set using the code below:
data string;
length var1 var2 $ 10;
input var1 $ var2 $;
datalines;
ABC DEF
abc def
1234 5678
;
run;
Remove Trailing Spaces from Text
When concatenating variables in SAS, you might get unwanted spaces between the values being combined.
data string2;
set string;
comb = var1 || var2;
run;
The VAR1 and VAR2 variables are concatenated into the COMB variable.
There are blank spaces between the two values:
There are blank spaces between the two values:

The blank spaces come from the trailing spaces from the VAR1 variable.
You can use the TRIM function to remove them:
data string2;
set string;
comb = trim(var1) || var2;
run;
The TRIM function removes the trailing spaces from the VAR1 variable.
The character values are concatenated with the unwanted spaces removed:
The character values are concatenated with the unwanted spaces removed:
Become a Certified SAS Specialist
Get access to two SAS base certification prep courses and 150+ practice exercises