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

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
ballardw
Super User

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..

 

 

 

Tom
Super User Tom
Super User

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
;
Tom
Super User Tom
Super User

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.

Aleixo
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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