How to combine data

Reply
Contributor
Posts: 67

How to combine data

Hi,

I try to combine the values in one column, see example:

IDDATA1DATA2DATA3DATA4DATA5

WANT TO GET

A1 D2 D4 D2,D4
A2D1 D3 D5 D1,D3,D5
A3 D2 D5 D2,D5
A4 D3D4 D3,D4

so I want to concatenate the values as "want to get" column.

let say, if I have column DATA1 to DATA100, is there a simple code to do the concatenation?

Any help will be appreciate!

Contributor
Posts: 52

Re: How to combine data

A solution:

data t_a;
length d1 d2 d3 d4 d5 $2.;
d1='';     d2='d2'; d3='';   d4='d4'; d5='';   output;
d1='d1';   d2='';   d3='d3'; d4='';   d5='d5'; output;
d1='';     d2='d2'; d3='';   d4='';   d5='d5'; output;
d1='';     d2='';   d3='d3'; d4='d4'; d5='';   output;
run;


data t_a;
  array d(*) $ d1-d5;
  set t_a;
  want_to_get= catx(',', of d(*));
run;

Contributor
Posts: 67

Re: How to combine data

Thank you very much for the code.

After I switch the order of array and set statement, then it works!

Super Contributor
Posts: 275

Re: How to combine data

data want;

   set have;

   length col  $200.;

   col=catx(',',of dataSmiley Happy;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 268 views
  • 1 like
  • 3 in conversation