SUPPORT / SAMPLES & SAS NOTES
 

Support

Usage Note 24513: What is the difference in using the SAS function CATS to concatenate text strings versus using the TRIM and LEFT functions with the concatenation operator (||)?

DetailsAboutRate It

The results of concatenating text strings are equivalent with both methods. However, the CATS function uses less code and processes the concatenation faster than the combination method, which uses multiple calls.

The CATS function is similar to the CATX function in that both functions concatenate strings as well as remove leading and trailing blanks. However, unlike the CATX function, CATS does not insert separators into the string.

Example 1: Creating a SAS Date Constant by Using the Combination Method

The following example uses the combination method to create a SAS date constant in the format '05Jun2006'd:

   data _null_;
      month="Jun ";
      day=" 05 ";
      year=" 2006 ";
      date="'"||trim(left(day))||trim(left(month))
              ||trim(left(year))||"'d";
      put date= ;
   run;

Example 2: Creating a SAS Date Constant by Using the CATS Function

The following code returns the same value (‘05Jun2006’d) as that shown in Example 1. However, the code in this example consolidates the concatenation in one call (the CATS function), which saves time both in coding and in processing:

   data _null_;
      month="Jun ";
      day=" 05 ";
      year=" 2006 ";
      date=cats("'", day, month, year,"'d");
      put date= ;
   run;

For detailed information, see "CATS Function" in SAS Language Reference: Dictionary under Base SAS in SAS OnlineDoc 9.1.3.

page divider

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.



Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemBase SASAlln/a
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.