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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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