merging 2 columns

Reply
Contributor LRN
Contributor
Posts: 57

merging 2 columns

Hi,

I have 15 columns in a dataset. out of these, one column have the group name and the other column have the subgroup name. i would like to merge only these two columns(all the other columns unchanged) so that under each group all the subgroups should be coming.  Please advise

Thank you

LR

Super User
Super User
Posts: 7,395

Re: merging 2 columns

As long as they are the only two in the datasets which have the same name then its simple;

/* Note, I assume you sort your data by the two variables first! */

data want;

     merge have1 have2;

     by variable1 variable2;

run;

However if one dataset has variables which are the same name as the other then you will get warnings.  You will then need to rename them in one dataset or the other.  For instance if variable4 was in both:

data want;

     merge have1 have2 (rename=(variable4=new_variable));

     by variable1 variable2;

run;

Valued Guide
Posts: 858

Re: merging 2 columns

It sounds to me that you mean concatenate variables, not merge.  Is that right?  Can you give an example of the data you have and the data you want?

Ask a Question
Discussion stats
  • 2 replies
  • 182 views
  • 0 likes
  • 3 in conversation