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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1608 views
  • 3 likes
  • 3 in conversation