Master SAS in 30 days!

A jargon-free, easy-to-learn SAS base course that is tailor-made for students with no prior knowledge of SAS.

The CAT, CATT, CATS, CATX functions in SAS

The CAT, CATT, CATS and CATX functions are used to concatenate character variables in SAS.

Example

In this data set, there are 3 character columns: COL1, COL2 and COL3.
 

The CAT Function

The CAT function concatenates character variables similar to the concatenation operator (||).

Data Columns2;
Set Columns;
Col_all = cat(col1, col2, col3);
Run;

In this example, the CAT function concatenates the COL1, COL2 and COL3 listed in the parameters:
 
The 3 columns are concatenated into one.

Please note that there are leading and trailing spaces in all of the COL1, COL2 and COL3 variables.
 
The spaces are captured in the concatenated variable:
 
 
In order to remove the leading and trailing spaces, we can make use of the CATT and CATS functions.
 
 

The CATT Function

The CATT function is similar to the CAT function. However, it removes the trailing spaces before concatenating the variables.

Example

Data Columns2;
Set Columns;
Col_all = catt(col1, col2, col3);
Run;

The CATT function concatenates the variables with the trailing spaces removed:
 
Now, we'll remove the leading spaces using the CATS function.

The CATS Function

The CATS function removes both the leading and trailing spaces before concatenating the variables.

Example

Data Columns2;
Set Columns;
Col_all = cats(col1, col2, col3);
Run;

The leading and trailing spaces are removed from the COL1, COL2 and COL3 variables before the variables are being concatenated. 

There is no space between the 3 character values in the concatenated variable.
 

This doesn't look good! We do need a space between the 3 columns.

We can use the CATX function to separate the values with a delimiter.

Do you have a hard time learning SAS?

Take our Practical SAS Training Course for Absolute Beginners and learn how to write your first SAS program!

The CATX Function

In addition to removing the leading and trailing spaces, the CATX function inserts a delimiter between the character values when concatenating the variables.

Example

Data Columns2;
Set Columns;
Col_all = catx(' ', col1, col2, col3);
Run;

The first parameter in the CATX function is the delimiter. In our example, the space is specified as the delimiter:

Data Columns2;
Set Columns;
Col_all = catx(' ', col1, col2, col3);
Run;

A single space is added between COl1 and COL2 as well as COL2 and COL3 columns.

The 3 columns are now combined and become a complete sentence.

Master SAS in 30 Days

5 1 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
subash
subash
2 months ago

Short and sweet

iconmail

Get latest articles from SASCrunch

SAS Base Certification Exam Prep Course

Two Certificate Prep Courses and 300+ Practice Exercises