![]() | ![]() | ![]() | ![]() |
The results of concatenating text are equivalent with both methods. However, the CATX function requires less code and processes the concatenation faster than the combination method, which uses multiple calls.
The following examples show the difference in coding for both methods. Notice that in these examples,
Example 1: Concatenating First and Last Names by Using the Combination Method
memname=trim(left(firstname) || ' ' || left(lastname);
Example 2: Concatenating First and Last Names by Using the CATX Function
memname=catx(' ', firstname, lastname);
For environments that support variable lists, you can use the OF syntax in the CATX function to condense variable lists that you are concatenating (Example 4 below). Note: In the following examples, separator specifies the character string of your choice (comma, blank, and so on) that will be used to separate the concatenated strings.
Example 3: Concatenating a Variable List by Using the Combination Method
x=trim(left(x1)) || separator || trim(left(x2)) ||separator || trim(left(x3)) || separator || trim(left(x4));
Example 4: Concatenating a Variable List by Using the CATX Function
x=catx(separator, of x1-x4);
For detailed information, see "CATX Function" in SAS Language Reference: Dictionary under Base SAS in SAS OnlineDoc 9.1.3.
About the Author
This tip was suggested by Nina L. Werner. Nina is a SAS programmer with more years experience than she wants to say.
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | Base SAS | All | n/a |