- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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