SAS concatenate: sas catx, sas catt, sas cats

sas string functions, sas concatenate, sas catx,  catx, sas concat, sas cats, sas catt, sas cat function, sas concatenate function, cat string, sas concatenate string, catx function in sas example, concatenate in sas data step, concatenate function

SAS concatenate: sas catx, sas catt, sas cats

sas concatenate, sas catx,  catx, sas concat, sas cats, sas catt, sas cat function, sas concatenate function, cat string, sas concatenate string, catx function in sas example, concatenate in sas data step, concatenate function

This Udemy course may interest you:
Complete & Practical SAS

Introduction

SAS catx(q)(t)(s) are part of the wonderful sas string functions! To begin, when you see or hear the words sas concatenate, this refers to combining or joining things. To be specific, I will show you sas string concatenation using sas data step. Our focus will be the catx function. In SAS 9, the ability to join or combine became easier with the introduction of the CAT functions. The syntax is now easier to read, there is the ability to use shorthand notation, and catx and catq do some things automatically so you don’t have to worry about it.

Catx

Let’s start with the catx sas function. Catx is a good starting point because it is quite sophisticated compared to some of the other functions (cat, cats, catt), and you will probably use it more often.

In the introduction, I mentioned that catx does some things for you automatically. First of all,  catx will automatically convert any numerical value passed as an argument into a string. Second of all, you don’t have to worry about duplicate delimiters because of blank strings.

Concatenate In SAS Data Step With Catx

First of all, let’s look at the syntax.

CATX(delimiter, item-1<, …item-n>)

As you can see, the first argument is a delimiter. The rest of the arguments or parameters will be the variables in question.

Now, let’s look at an example. You will notice in the example below that we have what are called leading blanks (in the first name variable) and trailing blanks (last name variable). We also have a delimiter, and the separator variable represents that situation. So what does SAS catx do for us? SAS catx will get rid of the leading blanks, the trailing blanks, and allow us to include whatever delimiter our file may use. 

data myexample;

separator =’,’

first=’     Larry’

last=’Smith         ‘

result=catx(separator,first,last)

drop separator

run;

The final thing I will mention is the ability to use shorthand notation. Instead of writing one variable and then a comma, then the next variable and then a comma, you can simply write OF and then first variable – last variable.

CATX(Delimiter, OF X1-X4)

The Other CATS – CAT,CATT,CATS

We certainly don’t want the rest of the cats to be ignored, as angry cats are dangerous.

The SAS CAT function is the simplest of the functions. It will simply join your character strings end-to-end.

CAT(OF X1-X4)

CATT is similar to CAT but it also removes trailing blanks.

CATT(OF X1-X4)

CATS is another variation and it will remove leading and trailing blanks.

CATS(OF X1-X4)

In conclusion, remember, CATX is in essence the big cat. If it makes sense to use it, do so.

Written by Ermin

You might be interested in this article:

SAS vs SPSS

Leave a Reply

Your email address will not be published. Required fields are marked *