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
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;
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;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.