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 . .*/
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
@Ronein did you find your answer to your previous thread?
If so, please remember to close the thread.
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.