SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3

Concatenates character strings, removes leading and trailing blanks, and inserts separators

Category: Character

Syntax

CATX ( separator , string-1 <, ... string-n >)

Arguments

separator

string

Details

The CATX function returns a value to a variable, or returns a value in a temporary buffer. The value that is returned from the CATX function has a length of up to

If CATX 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 CATX 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

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

Comparisons

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))

Examples

The following example shows how the CATX function concatenates strings.

data _null_; separator='%%$%%'; x='The Olympic '; y=' Arts Festival '; z=' includes works by '; a='Dale Chihuly.'; result=catx(separator,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 Olympic%%$%%Arts Festival%%$%%includes works by%%$%%Dale Chihuly.

See Also

Functions and CALL Routines:

Категории