When processing text data in Base SAS©, there are two constantly recurring operations: cleaning up unnecessary spaces and joining parts of text.
A simple question on the forum ('What is the difference between TRIM and CONCAT?') raised several important technical points about handling character strings.
1. TRIM: The Space Remover
In SAS©, a character variable has a fixed length. If you define a 10-character variable and store the word "CAT" in it, SAS© pads the remaining 6 characters with spaces. This is called trailing blanks.
The TRIM function is used to remove these trailing spaces.
Example: If
VAR1has the value'1234 '(with spaces).VAR2 = TRIM(VAR1);results in'1234'.
Technical Note: As a response clarifies,
TRIMdoes not affect spaces before the text (leading blanks). To remove spaces before and after the text,TRIM(LEFT(value))was historically used. Today, the functionSTRIPdoes this in a single step.
2. Concatenation: The Assembler
Concatenation is the process of joining two character strings together.
There was some confusion in the original thread here. The user asks for a definition of the "CONCAT" function.
In standard Base SAS©, there was historically no function simply called "CONCAT". The operation is performed using the operator
||(double vertical bar) or!!.The complex technical answer in the forum (which mentions "character matrices") refers to the SAS©/IML module (matrix language), which is irrelevant for most classic users.
