BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Pyrite | Level 9

## re: Catx Function Error

Hi....I am using the Catx Function in a data step and get warning message. The code and warning message are as follows:

DATA WANT;
SET TRANSPOSED;
ARRAY c col: ;
FINAL = catx(' : ', of c(*));
RUN;

WARNING: In a call to the CATX function, the buffer allocated for the result was not
long enough to contain the concatenation of all the arguments. The correct
result would contain 262 characters, but the actual result may either be
truncated to 200 character(s) or be completely blank, depending on the calling
environment. The following note indicates the left-most argument that caused
truncation.

1 ACCEPTED SOLUTION

Accepted Solutions
Rhodochrosite | Level 12

## Re: re: Catx Function Error

Hi, you can determine the length you need in a data step ...

* fake data;

data transpose;
retain col1-col100 1234;
output;
col100 = 12345678901234567890; output;
col100 = 1; output;
run;

data _null_;
set transpose end=last;
ll + max(ll, length(catx(':', of col: ))) - ll;
if last then call symputx('length',ll);
run;

* use macro variable, no array;

data want (keep=xyz);
length xyz \$&length.;
set transpose;
xyz = catx(':', of col: );
run;

PROC CONTENTS ...

Alphabetic List of Variables and Attributes

#    Variable    Type    Len

1    xyz         Char    515

5 REPLIES 5
Barite | Level 11

## Re: re: Catx Function Error

The error is always appreciated but to get a more complete answer I recommend adding the data you have and the data you want.

So give an example dataset 'transposed'  and 'want'.

Mark

Opal | Level 21

## Re: re: Catx Function Error

Per default variable "FINAL" gets a length of \$200. This appears to be too short to hold the result of your catx() function.

Assign an appropriate length to "FINAL" and things will work.

``````DATA WANT;
SET TRANSPOSED;
ARRAY c col: ;
length FINAL \$262;
FINAL = catx(' : ', of c(*));
RUN;``````
Pyrite | Level 9

## Re: re: Catx Function Error

Hi Patrick.....thanks for you help. I did try including the Length Statement and I get the following warning mesaage:

WARNING: In a call to the CATX function, the buffer allocated for the result was not
long enough to contain the concatenation of all the arguments. The correct
result would contain 327 characters, but the actual result may either be
truncated to 262 character(s) or be completely blank, depending on the calling
environment. The following note indicates the left-most argument that caused
truncation.

I did try using the compress function and the error message was gone but I don't want to remove blanks.

Super User

## Re: re: Catx Function Error

Looks like you need to know your data. You need to set the length of the target variable large enough to take the longest string it will generate. So SUM the DEFINED lengths of all of the C: variables and the number of characters that will be inserted for the delimiter by CATX and that would be a minimum.

Rhodochrosite | Level 12

## Re: re: Catx Function Error

Hi, you can determine the length you need in a data step ...

* fake data;

data transpose;
retain col1-col100 1234;
output;
col100 = 12345678901234567890; output;
col100 = 1; output;
run;

data _null_;
set transpose end=last;
ll + max(ll, length(catx(':', of col: ))) - ll;
if last then call symputx('length',ll);
run;

* use macro variable, no array;

data want (keep=xyz);
length xyz \$&length.;
set transpose;
xyz = catx(':', of col: );
run;

PROC CONTENTS ...

Alphabetic List of Variables and Attributes

#    Variable    Type    Len

1    xyz         Char    515

Discussion stats
• 5 replies
• 21095 views
• 3 likes
• 5 in conversation