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.
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
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
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;
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.
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: