Help using Base SAS procedures

Data merge with different field names

Reply
Contributor
Posts: 59

Data merge with different field names


data trial;

merge trial1

         trial2;

by  ???

run;

trial1 has the field gen_id

trial2 has the field sys_id

they are an equal join but with different names.  If they had the same name it would be a simple by statement.  How can I join these two when they have equal value and different names?

Super Contributor
Posts: 418

Re: Data merge with different field names

data trial;

merge trial1(rename=(gen_id=sys_id)) trial2;

by sys_id;

run;


Respected Advisor
Posts: 3,124

Re: Data merge with different field names

Choose the "id" you want to keep and rename the other one:

data trial;

   merge trial1 /*keeping gen_id*/

             trial2 (rename=sys_id=gen_id);

by gen_id;

run;

Or without renaming/Sorting, use

Proc sql;

   create table trail as

    select *  from trail1 a, trial2 b where  a.gen_id=b.sys_id;

quit;

Haikuo

Super Contributor
Posts: 578

Re: Data merge with different field names

proc sql;

create table trial as

select

     *

from

     trial1 t1

     inner join trial2 t2

          on t1.gen_id=t2.sys_id;

quit;

Ask a Question
Discussion stats
  • 3 replies
  • 143 views
  • 0 likes
  • 4 in conversation