DATA Step, Macro, Functions and more

How to concatenate a culomn values into a string?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How to concatenate a culomn values into a string?

I have a table like this

data concat;

input name $;

datalines;

a

b

c

d

;

run;

How can I turn values of culomn 'name' into a single string of  a, b, c, d?


Accepted Solutions
Solution
‎02-21-2012 01:43 AM
PROC Star
Posts: 7,484

How to concatenate a culomn values into a string?

Not sure how you want to use it, but one way would be:

data concat;

input name $;

datalines;

a

b

c

d

;

run;

proc sql noprint;

  select name

    into :string

      separated by ","

        from concat

  ;

quit;

%put &string.;

View solution in original post


All Replies
Solution
‎02-21-2012 01:43 AM
PROC Star
Posts: 7,484

How to concatenate a culomn values into a string?

Not sure how you want to use it, but one way would be:

data concat;

input name $;

datalines;

a

b

c

d

;

run;

proc sql noprint;

  select name

    into :string

      separated by ","

        from concat

  ;

quit;

%put &string.;

Occasional Contributor
Posts: 8

How to concatenate a culomn values into a string?

Thanks, It works Smiley Happy

Super User
Posts: 10,041

How to concatenate a culomn values into a string?

Or data step.

data concat;
input name $;
datalines;
a
b
c
d
;
run;
data want(keep=len);
 set concat end=last;
 length len $ 32767;
 retain len;
 len=catx(', ',len,name);
 if last then output;
run;


Ksharp

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 1208 views
  • 0 likes
  • 3 in conversation