☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-03-2022 01:47 PM
(1434 views)
Hello,
Struggling with the below. Basically I shouldn't be having multiple rows of same id. At the same time, their corresponding values of 'Desc' filed, has to be combined.
Data have:
ID Desc
1234 AB
5678 CD
5678 EF
9999 GH
Data want:
ID Desc
1234 AB
5678 CD_EF
9999 GH
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input ID DESC $2.;
datalines;
1234 AB
5678 CD
5678 EF
9999 GH
run;
data want(keep=id list);
do until (last.id);
set have;
by id;
length list $30;
list = catx('_',list,desc);
end;
run;
gives
ID | list |
1234 | AB |
5678 | CD_EF |
9999 | GH |
Not my code.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input ID DESC $2.;
datalines;
1234 AB
5678 CD
5678 EF
9999 GH
run;
data want(keep=id list);
do until (last.id);
set have;
by id;
length list $30;
list = catx('_',list,desc);
end;
run;
gives
ID | list |
1234 | AB |
5678 | CD_EF |
9999 | GH |
Not my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello HB,
Thanks for taking your time and providing the solution. Appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just another way --
data have;
input ID DESC $2.;
datalines;
1234 AB
5678 CD
5678 EF
9999 GH
run;
proc transpose data=have out=have_t(drop=_:);
by id;
var DESC;
run;
data want(drop=col:);
set have_t;
desc=catx("_", of col:);
run;