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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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?

anon_pvok
Fluorite | Level 6

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

novinosrin
Tourmaline | Level 20

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. 

Tom
Super User Tom
Super User

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;
anon_pvok
Fluorite | Level 6

Now my question seems silly, thank you very much. The above mentioned solved my problem.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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