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
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.
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.
Hello HB,
Thanks for taking your time and providing the solution. Appreciated.
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;
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!
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.