DATA Step, Macro, Functions and more

How to concatenate all the values in a column?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to concatenate all the values in a column?

eg : I have  5 names under the column "User" in a dataset, how do I get the result as  AB;BC;CD;DE;EF where AB,BC,CD,DE,EF are the values under the column "User" .


Accepted Solutions
Solution
‎09-02-2013 09:59 PM
Respected Advisor
Posts: 4,640

Re: How to concatenate all the values in a column?

Like this:

data have;
input user :$2.;
datalines;
AB
BC
CD
DE
EF
;

data want(keep=userList);
length userList $24;
do until(eof);
     set have end=eof;
     userList = catx(";", userList, user);
     end;
run;

proc print data=want noobs; run;

PG

PG

View solution in original post


All Replies
Solution
‎09-02-2013 09:59 PM
Respected Advisor
Posts: 4,640

Re: How to concatenate all the values in a column?

Like this:

data have;
input user :$2.;
datalines;
AB
BC
CD
DE
EF
;

data want(keep=userList);
length userList $24;
do until(eof);
     set have end=eof;
     userList = catx(";", userList, user);
     end;
run;

proc print data=want noobs; run;

PG

PG
Occasional Contributor
Posts: 10

Re: How to concatenate all the values in a column?

I'd like to know, how it's possible to concatenate one column and mantain the information in each row. For example:

A B

a 1

a 2

a 3

b 4

b 5

b 6

c 7

d 8

e 9

e 10

f 11

 

Create 3 columns like this:

A    B     Concatenate

a    1     1,2,3

a    2     1,2,3

a    3     1,2,3

b    4     4,5,6

b    5     4,5,6

b    6     4,5,6

 

 

Thanks in advance for your help!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1407 views
  • 0 likes
  • 3 in conversation