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

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
MikeZdeb
Rhodochrosite | Level 12

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

5 REPLIES 5
Steelers_In_DC
Barite | Level 11

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

Patrick
Opal | Level 21

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;
twildone
Pyrite | Level 9

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.

ballardw
Super User

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.

MikeZdeb
Rhodochrosite | Level 12

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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