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

Hello

I have a row data that contain multiple rows per customer.

I want to concatenate the values in column  "Loc" and the remerge it with original data set

 

Data tbl;
input ID  Loc $;
cards;
1 .
1 .
1 3
1 .
1 5
2 .
2 .
2 3
2 .
2 .
3 .
3 .
3 .
3 .
3 .
;
run;
/*Required data set*/
/*1 .  3,5*/
/*1 .  3,5*/
/*1 3  3,5*/
/*1 .  3,5*/
/*1 5  3,5*/
/*2 .  3*/
/*2 .  3 */
/*2 3  3*/
/*2 .  .*/
/*2 .  .*/
/*3 .  .*/
/*3 .  .*/
/*3 .  .*/
/*3 .  .*/
/*3 .  .*/
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data want;
    do until (last.id);
        set tbl;
        length con $ 200;
        by id;
        if not missing(Loc) then con=catx(',', con, Loc);
    end;
    do until (last.id);
        set tbl;
        by id;
        output;
    end;
run;

Result:

 

ID   Loc   con
1          3,5
1          3,5
1    3     3,5
1          3,5
1    5     3,5
2    3
2    3
2    3     3
2    3
2    3
3  
3  
3  
3  
3  

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

@Ronein did you find your answer to your previous thread?

 

https://communities.sas.com/t5/SAS-Programming/calculate-number-of-distinct-values-between-rows-for-...

 

If so, please remember to close the thread.

PeterClemmensen
Tourmaline | Level 20
data want;
    do until (last.id);
        set tbl;
        length con $ 200;
        by id;
        if not missing(Loc) then con=catx(',', con, Loc);
    end;
    do until (last.id);
        set tbl;
        by id;
        output;
    end;
run;

Result:

 

ID   Loc   con
1          3,5
1          3,5
1    3     3,5
1          3,5
1    5     3,5
2    3
2    3
2    3     3
2    3
2    3
3  
3  
3  
3  
3  

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 367 views
  • 1 like
  • 2 in conversation