Hi everyone -
I am trying to add multiple text strings onto a single record.
From something like this:
ID TEXT_1 TEXT_2
001 aaaaa bbbbb
002 ccccc ddddd
Here is what I'd like to achieve:
ID TEXT_3
001 aaaaa
bbbbb
002 ccccc
ddddd
Any help would be greatly appreciated. Thanks,
Like this:
data really_want;
set want(rename = (col1 = text_3 ) drop = _NAME_);
by id;
if not first.id then id = "";
run;
Can it be like this?
ID TEXT_3
001 aaaaabbbbb
002 cccccddddd
then:
text_3 = compress(text_1,text_2);
or do you want it like this?
ID TEXT_3
001 aaaaa
001 bbbbb
002 ccccc
002 ddddd
proc transpose data = in out = want;
by id;
var text_1 text_2;
run;
data really_want;
set want(rename = (col1 = text_3 ) drop = _NAME_);
run;
Thanks, Anca. Is there a way to get rid of the multiple IDs. I used array to get to the same result as you did with the transpose though.
ID TEXT
001 aaaaa
bbbbb
002 ccccc
ddddd
Like this:
data really_want;
set want(rename = (col1 = text_3 ) drop = _NAME_);
by id;
if not first.id then id = "";
run;
Let me suggest that getting rid of the multiple IDs is a bad idea. You don't have to print them, even with PROC PRINT you can try:
proc print;
var text;
by id;
id id;
run;
And you have even more choices if you learn PROC REPORT. But if you get rid of the multiple IDs you will have to jump through hoops if you ever want to sort your data.
Good luck.
Very helpful tips. Thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.