I have a data set with Character columns named like Col1, Col2 ... ColN.
I want to concatenate these columns with a deliminator separator.
I tried using catx as mentioned below but the result was greater than 200 Characters, therefore was getting NULL in the resulting Dataset.
DATA WORK.FINAL (KEEP=IDT KEYWORDS); SET WORK.TEMP; KEYWORDS=CATX('~', of COL:); RUN;
The CATX() function does not have a limit of 200 characters. The problem is you did not tell the data step how long to make KEYWORDS. So it had to guess and it guessed to use $200 since you where assigning it the value of a function that can return character values.
DATA FINAL;
SET TEMP;
length keywords $32767 ;
KEYWORDS=CATX('~', of COL:);
KEEP IDT KEYWORDS ;
RUN;
HI @anon_pvok Not sure what you mean by "I tried using catx as mentioned below but the result was greater than 200 Characters, therefore was getting NULL in the resulting Dataset."
You could always assign a length using LENGTH statement before your CATX assignment. Am i missing something?
EDIT: Kindly Ignore the below comment. Adding a length Statement solved the issue.
CATX Only allows 200 Characters.
When I run the above code i get the below warning message.
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 1897 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 thee left-most argument that caused truncation
There you go @anon_pvok , @Tom has clarified that it isn't a "Limit" rather a default setting. I am pretty certain you could assign a length of upto $32767 bytes, and this number is the limit.
The CATX() function does not have a limit of 200 characters. The problem is you did not tell the data step how long to make KEYWORDS. So it had to guess and it guessed to use $200 since you where assigning it the value of a function that can return character values.
DATA FINAL;
SET TEMP;
length keywords $32767 ;
KEYWORDS=CATX('~', of COL:);
KEEP IDT KEYWORDS ;
RUN;
Now my question seems silly, thank you very much. The above mentioned solved my problem.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.