Previous Page | Next Page

Functions and CALL Routines

CAT Function



Does not remove leading or trailing blanks, and returns a concatenated character string.
Category: Character
Restriction: I18N Level 2
Tip: DBCS equivalent function is KSTRCAT in SAS National Language Support (NLS): Reference Guide.

Syntax
Arguments
Details
Length of Returned Variable
Length of Returned Variable: Special Cases
Comparisons
Examples
See Also

Syntax

CAT(item-1 <, ..., item-n>)


Arguments

item

specifies a constant, variable, or expression, either character or numeric. If item is numeric, then its value is converted to a character string by using the BESTw. format. In this case, leading blanks are removed and SAS does not write a note to the log.


Details


Length of Returned Variable

In a DATA step, if the CAT function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes. If the concatenation operator (||) returns a value to a variable that has not previously been assigned a length, then that variable is given a length that is the sum of the lengths of the values which are being concatenated.


Length of Returned Variable: Special Cases

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 the following length:

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 does the following:

The CAT function removes leading and trailing blanks from numeric arguments after it formats the numeric value with the BESTw. format.


Comparisons

The results of the CAT, CATS, CATT, and CATX functions are usually equivalent to results that are produced by certain combinations of the concatenation operator (||) and the TRIM and LEFT functions. However, the default length for the CAT, CATS, CATT, and CATX functions is different from the length that is obtained when you use the concatenation operator. For more information, see Length of Returned Variable.

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 delimiter, such as a blank or comma.

Function Equivalent Code
CAT(OF X1-X4)
X1||X2||X3||X4
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))||SP||TRIM(LEFT(X2))||SP||
TRIM(LEFT(X3))||SP||TRIM(LEFT(X4))


Examples

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;

SAS writes the following line to the log:

   ----+----1----+----2----+----3----+----4----+----5----+----6----+----7
     The 2002 Olympic Arts Festi  val included works by D  ale Chihuly.


See Also

Functions and CALL Routines:

CALL CATS Routine

CALL CATT Routine

CALL CATX Routine

CATQ Function

CATS Function

CATT Function

CATX Function

Previous Page | Next Page | Top of Page