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.

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