generate multiple text strings on a single record

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

generate multiple text strings on a single record

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,


Accepted Solutions
Solution
‎04-16-2013 02:17 PM
Super Contributor
Posts: 543

Re: generate multiple text strings on a single record

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


All Replies
Super Contributor
Posts: 543

Re: generate multiple text strings on a single record

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

Occasional Contributor
Posts: 13

Re: generate multiple text strings on a single record

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

Solution
‎04-16-2013 02:17 PM
Super Contributor
Posts: 543

Re: generate multiple text strings on a single record

Like this:

data really_want;

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

   by id;

    if not first.id then id = "";

run;

Super User
Posts: 5,072

Re: generate multiple text strings on a single record

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.

Occasional Contributor
Posts: 13

Re: generate multiple text strings on a single record

Very helpful tips. Thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 218 views
  • 3 likes
  • 3 in conversation