Hello,
Below is what I HAVE and what I WANT
The problem that i have is the delimiter. I have COMMA inside the column value and also after concatenation, I need to have comma as a separator.
In my actual data, these are First Names and Last Names. So if a person's name is repeated, I keep that person's name only once.
Please advise.
data have;
infile datalines dlm="|";
input id n1 :$4. n2 :$4. n3 :$4. n4 :$4.;
datalines;
1|a,b| |a,b|d
2|a| | |
3|a,b| |b,d|d
4| |b| |d
;
run;
data want;
infile datalines dlm="|";
input id final $16.;
datalines;
1|a,b , d
2|a
3|a,b , b,d , d
4|b , d
;
run;
data have;
infile datalines dlm="|";
input id n1 :$4. n2 :$4. n3 :$4. n4 :$4.;
datalines;
1|a,b| |a,b|d
2|a| | |
3|a,b| |b,d|d
4| |b| |d
;
run;
data want;
set have;
length final $ 200;
array x{*} $ n1-n4;
do i=1 to dim(x);
if not findw(final,strip(x{i}),'|') then final=catx('|',final,x{i});
end;
final=tranwrd(final,'|',' , ');
keep id final;
run;
data have;
infile datalines dlm="|";
input id n1 :$4. n2 :$4. n3 :$4. n4 :$4.;
datalines;
1|a,b| |a,b|d
2|a| | |
3|a,b| |b,d|d
4| |b| |d
;
run;
data want;
set have;
length final $ 200;
array x{*} $ n1-n4;
do i=1 to dim(x);
if not findw(final,strip(x{i}),'|') then final=catx('|',final,x{i});
end;
final=tranwrd(final,'|',' , ');
keep id final;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.