DATA Step, Macro, Functions and more

CATX function buffer always truncated to 16

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

CATX function buffer always truncated to 16

[ Edited ]

Hi,

 

I try to do this code:

proc sql;
update WORK.List
set New= catx('-', put(substr(New, 7, 4), $4.), put(datepart(Date), yymmdd10.), Name)
  , Name=case when Name LIKE '%NOVA' then substr(Name, 1, length(Name)-4) end
;

 

I have this error:

 

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 30 characters, but the actual result might either be truncated to 16 
         character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most 
         argument that caused truncation.
WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the concatenation of 
2                                                          The SAS System                               14:03 Friday, March 16, 2018

         all the arguments. The correct result would contain 35 characters, but the actual result might either be truncated to 16 
         character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most 
         argument that caused truncation.

The result is a column in blanks, not the string truncated to 16, i don't understand what means calling environment to be completely blank.

I try to change length in proc sql like:

t1.New format=$100.,  but always same error. I think is because de limitation of buffer in catx.

 

How i can solve this problem?

 

Regards,

Aleixo

 

 

 


Accepted Solutions
Solution
‎03-16-2018 01:36 PM
Super User
Super User
Posts: 8,279

Re: CATX function buffer always truncated to 16

I try to change length in proc sql like:

t1.New format=$100.,

Changing the format attached to a variable does NOT change the length.  If you want to set the LENGTH then use LENGTH= option instead. Note that in an SQL SELECT statement the value of the LENGTH= does not include the $ prefix for character variables as it does in the normal LENGTH statement you would use in a data step.

 

create table newtable as
  select a,b,c,catx('_',a,b,c) as new length=100 
  from oldtable
;

View solution in original post


All Replies
Super User
Posts: 13,941

Re: CATX function buffer always truncated to 16

Since I see this line:

 

update WORK.List

then that means that the variable NEW already exists in your data set. It probably has a length of 16 which is not likely to change with an UPDATE which means "change in place"

 

Try creating a new table..

 

 

 

Solution
‎03-16-2018 01:36 PM
Super User
Super User
Posts: 8,279

Re: CATX function buffer always truncated to 16

I try to change length in proc sql like:

t1.New format=$100.,

Changing the format attached to a variable does NOT change the length.  If you want to set the LENGTH then use LENGTH= option instead. Note that in an SQL SELECT statement the value of the LENGTH= does not include the $ prefix for character variables as it does in the normal LENGTH statement you would use in a data step.

 

create table newtable as
  select a,b,c,catx('_',a,b,c) as new length=100 
  from oldtable
;
Super User
Super User
Posts: 8,279

Re: CATX function buffer always truncated to 16

If you want more control over which 16 characters from your concatenated string are stored into the 16 character long variable NEW you could add a SUBSTR() function call.

proc sql;
update WORK.List
set New= substr(catx('-', substr(New, 7, 4), put(datepart(Date), yymmdd10.), Name),1,16)
  , Name=case when Name LIKE '%NOVA' then substr(Name, 1, length(Name)-4) end
;

Note there is no need to use PUT() around the substr() function you had before.

Contributor
Posts: 70

Re: CATX function buffer always truncated to 16

Thank you very much all answers.

 

Tom i think is update statement you will update all observations. We have to add a else statement to update only the observations that you want. Am i right?

 

regards,

aleixo

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 271 views
  • 0 likes
  • 3 in conversation