DATA Step, Macro, Functions and more

re: Catx Function Error

Accepted Solution Solved
Reply
Regular Contributor
Posts: 229
Accepted Solution

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.

 


Accepted Solutions
Solution
‎10-14-2015 03:42 PM
Valued Guide
Posts: 765

Re: re: Catx Function Error

[ Edited ]

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

View solution in original post


All Replies
Valued Guide
Posts: 860

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

Respected Advisor
Posts: 4,173

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;
Regular Contributor
Posts: 229

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
Posts: 11,343

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.

Solution
‎10-14-2015 03:42 PM
Valued Guide
Posts: 765

Re: re: Catx Function Error

[ Edited ]

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 938 views
  • 0 likes
  • 5 in conversation