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

Hello,

 

I am trying to concatenate values from the same column in sas.  I have tried multiple versions of the cat function and am not able to get this to work properly.  There are blanks that I would like to use to cause the concatenation column to delete its previous values and start again with the current value.  I have an example below.  The Conc Column is my desired goal.  Any and all help would be greatly appreciated.  Thank you.

 

Column 1       Column2      Conc Column

a                     x1                 x1

b                     x2                 x1 x2

c                     x3                 x1 x2 x3

d

e                     x5                 x5

f                      x6                 x5 x6

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What did you try?  How did it not work?

data want;
  set have;
  length new_column $200;
  retain new_column;
  if column2 = ' ' then new_column=' ';
  else new_column=catx(' ',new_column,column2);
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

What did you try?  How did it not work?

data want;
  set have;
  length new_column $200;
  retain new_column;
  if column2 = ' ' then new_column=' ';
  else new_column=catx(' ',new_column,column2);
run;
Anthony_eng
Obsidian | Level 7

I tried using concatValue = cats(column1, '  ', column2); and it wasn't creating spaces between the concatenated values.  I also tried to use an IF-THEN-DO statement to retain the value, set the concatValue to blank space (= ' ') when needed, but I did it all in the IFTHEN statement.  I am guessing that was causing the issue.  I tried multiple iterations/changes and failed over and over.  Thanks for the help.

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
  • 2 replies
  • 335 views
  • 1 like
  • 2 in conversation