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

Hi,

 

Here is what my data looks like:

 

Unique ID      Col1      Col2     Col3     Col4

   1                Text1                  Text3

   2                Text1     Text2                 Text4

   3

   4                              Text2     Text3

 

I'm trying to create a new column that lists all the text from column 1 through 4, with commas and a single between the different texts, and that shows nothing when there is no text. Here's what I want:

 

Unique ID     NewCol

   1                Text1, Text3

   2                Text1, Text2, Text4

   3

   4                Text2, Text3

 

I can't seem to figure out a way with out creating ", , ," for line 3, and extra commas in the text strings (this creates a problem since I actually have 29 columns of text I'm trying to put in a text sting in a single column).

 

Any suggestions?

 

Amanda

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

In a datastep

 

new_col = catx(',',col1, col2,col3,col4);

 

the first argument in the catx function is the character(s) to place between the values indicated. Blanks are suppressed

View solution in original post

3 REPLIES 3
ballardw
Super User

In a datastep

 

new_col = catx(',',col1, col2,col3,col4);

 

the first argument in the catx function is the character(s) to place between the values indicated. Blanks are suppressed

amanda_cr
Calcite | Level 5
Works perfect! Thank you for your help!


amanda_cr
Calcite | Level 5

Works perfect and so simple! Thank you.

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