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

Hello!

I get this message when trying to concatenate.

WARNING:In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of all the arguments. The correct result would contain 5420 characters, but the actual result might 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.

NOTE: Argument 1 to function CATS('TUEF11846042'[12 of 32000 characters shown],'BC07BCC00210'[12 of 200 characters shown],'ES02**   '[12 of 32000 characters shown]) at line 1722 column 14 is invalid.

I have 3 character variables. Acct, Header, String; I need to add String inside Header after a certain criteria is met.

 Note: header is very long. A shortened version of it looks like this:

Header=016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000ES02**

String=BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3

I need to add String in Header after the last BC07(and its value) .

Header_new should look like: 016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3ES02**

This is my code:

 data want;set have;
  b= find(header,'BC07',-length(header));/*position of last 'BC07'*/
  length_of_value=input(substrn(header,find(header,'BC07',-length(header)) + 13),2.);
  frst_string=substrn(header,1, (find(header,'BC07',-length(header))) + 14 + (input(substrn(header,find(header,'BC07',-length(header)) + 13),2.)));
  last_string=substrn(header,b + 15 + length_of_value,length(header) - b + 15 + length_of_value);
  header_new=cats(frst_string,string,last_string); 
 run; 

Can anyone help me with this? I'm guessing the problem is with the length of the characters but I have no idea how to fix it.

Thanks in Advance.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

See Maxim 47: Set a Length.

Add

length header_new $5420;

before the function call.

The SAS datastep compiler defines most new character variables found to the left of a character function with a default length of 200 if no other is specified.

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Please try the below code

 

data have;
Header='016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000ES02**';
String='BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3';
string2=cats(substr(Header,1,prxmatch('m/ES02/oi',header)-1),String,substr(Header,prxmatch('m/ES02/oi',header),6));
run;
Thanks,
Jag
Kurt_Bremser
Super User

See Maxim 47: Set a Length.

Add

length header_new $5420;

before the function call.

The SAS datastep compiler defines most new character variables found to the left of a character function with a default length of 200 if no other is specified.

JT99
Obsidian | Level 7
Thank you! My code is now working!
Tom
Super User Tom
Super User

Your code has 5 assignment statements.  Do any of the variables being given values already exist in HAVE? 

If not then the SAS data step compiler will make a guess at how to define them.

The first two are assigning numeric values, so they will be created as numbers.

The next three are being assigned character values, so they will be created as character, but the compiler needs to make a guess at what length you wanted for them.  For the first two since it is the result of SUBSTRN() on HEADER they will be set to the same length as HEADER.

But the last one is the result of the CATS() function call.  So the compiler has no way to know what possible length to use, so it uses $200.

 

ALWAYS define your variables before using them.  You can use the LENGTH statement or the LENGTH= option on the ATTRIB statement.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 4028 views
  • 3 likes
  • 4 in conversation