Concatenates character strings without removing leading or trailing blanks
Category: Character
CAT ( string-1 <, ... string-n >)
string
specifies a SAS character string.
The CAT function returns a value to a variable, or returns a value in a temporary buffer. The value that is returned from the CAT function has a length of up to
200 characters in WHERE clauses and in PROC SQL
32767 characters in the DATA step except in WHERE clauses
65534 characters when string is called from the macro processor.
If CAT returns a value in a temporary buffer, the length of the buffer depends on the calling environment, and the value in the buffer can be truncated after CAT finishes processing. In this case, SAS does not write a message about the truncation to the log.
If the length of the variable or the buffer is not large enough to contain the result of the concatenation, SAS
changes the result to a blank value in the DATA step, and in PROC SQL
writes a warning message to the log stating that the result was either truncated or set to a blank value, depending on the calling environment
writes a note to the log that shows the location of the function call and lists the argument that caused the truncation
sets _ERROR_ to 1 in the DATA step.
The CAT function removes leading and trailing blanks from numeric arguments after it formats the numeric value with the BEST. format.
The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to those that are produced by certain combinations of the concatenation operator () and the TRIM and LEFT functions. However, using the CAT, CATS, CATT, and CATX functions is faster than using TRIM and LEFT, and you can use them with the OF syntax for variable lists in calling environments that support variable lists.
The following table shows equivalents of the CAT, CATS, CATT, and CATX functions. The variables X1 through X4 specify character variables , and SP specifies a separator, such as a blank or comma.
Function | Equivalent Code |
---|---|
CAT(OF X1-X4) | X1X2X3X4 |
CATS(OF X1-X4) | TRIM(LEFT(X1))TRIM(LEFT(X2))TRIM(LEFT(X3)) TRIM(LEFT(X4)) |
CATT(OF X1-X4) | TRIM(X1)TRIM(X2)TRIM(X3)TRIM(X4) |
CATX(SP, OF X1-X4) | TRIM(LEFT(X1))SPTRIM(LEFT(X2))SP TRIM(LEFT(X3))SPTRIM(LEFT(X4)) |
The following example shows how the CAT function concatenates strings.
data _null_; x=' The 2002 Olym'; y='pic Arts Festi'; z=' val included works by D '; a='ale Chihuly.'; result=cat(x,y,z,a); put result $char.; run;
The following line is written to the SAS log:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7 The 2002 Olympic Arts Festi val included works by D ale Chihuly.
Functions and CALL Routines:
'CATS Function' on page 412
'CATT Function' on page 414
'CATX Function' on page 416
'CALL CATS Routine' on page 337
'CALL CATT Routine' on page 338
'CALL CATX Routine' on page 340