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

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,

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

Like this:

data really_want;

    set want(rename = (col1 = text_3 ) drop =  _NAME_);

   by id;

    if not first.id then id = "";

run;

View solution in original post

5 REPLIES 5
AncaTilea
Pyrite | Level 9

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;

Smiley Happy

Kyle
Calcite | Level 5

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

AncaTilea
Pyrite | Level 9

Like this:

data really_want;

    set want(rename = (col1 = text_3 ) drop =  _NAME_);

   by id;

    if not first.id then id = "";

run;

Astounding
PROC Star

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.

Kyle
Calcite | Level 5

Very helpful tips. Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1038 views
  • 3 likes
  • 3 in conversation