I have an unusual task where I am given 3 lists that I merge together, and I am supposed to only report a single list of all distinct values found in all lists. Below is some code that I made up to illustrate the idea.
proc sql;
create table test (ID char(3), LIST1 char(10), LIST2 char(10), LIST3 char(10));
insert into test (id, list1, list2, list3)
values ('001', 'A,B,C', 'A,B,C', 'A,B,C')
values ('002', 'A,C,D', 'C', 'A,C,D')
values ('003', 'A,B,C,D,E', '', '')
values ('004', 'A,B,C,D,E', 'A,B', 'C,D,F');
quit;
I am wondering if there is a simple way to end up with the following results:
ID
LIST
001
A,B,C
002
A,C,D
003
A,B,C,D,E
004
A,B,C,D,E,F
The best I can think is to parse each item from each list into a separate variable, transpose from horizontal to vertical, remove any duplicate values, transpose from vertical to horizontal, then CATX everything again into a single list. Please tell me there is better way!
... View more