Hi,
I have a dataset as below
data REL_DATA;
input ENUM $ RELATED_ENUM $ ROLE $;
datalines;
D1234 R1234 84
D1234 R1234 85
D1234 L2345 90
D1234 P1234 81
D1234 N4567 90
D1234 N4567 88
;
run;
I want the output as below
ENUM RELATED_NUM ROLES
D1234 R1234 84,85
D1234 L2345 90
D1234 P1234 81
D1234 N4567 90,88
Basically if the Related_num is repeated for a different role, i want it to be merged to one row with the roles displayed in the ROLES column
Thank you.
If it was me, I would sort and transpose it and then concatenate all the values of role after transposing.
data REL_DATA;
input ENUM $ RELATED_ENUM $ ROLE $;
datalines;
D1234 R1234 84
D1234 R1234 85
D1234 L2345 90
D1234 P1234 81
D1234 N4567 90
D1234 N4567 88
;
run;
proc sort data=rel_data;
by enum related_enum;
run;
proc transpose data=rel_data out=rel_data_t(drop=_name_);
by enum related_enum;
var role;
run;
data rel_data_t2;
set rel_data_t;
roles=catx(',',of col:);
run;
If it was me, I would sort and transpose it and then concatenate all the values of role after transposing.
data REL_DATA;
input ENUM $ RELATED_ENUM $ ROLE $;
datalines;
D1234 R1234 84
D1234 R1234 85
D1234 L2345 90
D1234 P1234 81
D1234 N4567 90
D1234 N4567 88
;
run;
proc sort data=rel_data;
by enum related_enum;
run;
proc transpose data=rel_data out=rel_data_t(drop=_name_);
by enum related_enum;
var role;
run;
data rel_data_t2;
set rel_data_t;
roles=catx(',',of col:);
run;
@tarheel13 Thanks a ton... It did work for what I am trying to do ... 🙂
@Reeza Thank you very much . It helped... Appreciate it.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.