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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.