Learning SAS? Welcome to the exclusive online community for all SAS learners.

How to do one to one merging in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

How to do one to one merging in SAS

How to do one to one merging in SAS

 


Accepted Solutions
Solution
‎04-25-2016 03:51 PM
Super User
Posts: 10,500

Re: How to do one to one merging in SAS

You may need to expand on what you are thinking about with one to one merge. Do mean first record in the first data set with the first record of the second set regardless OR by matching the value of a variable in each set?

 

The first is easy:

 

data want;

   merge setone settwo;

run;

 

The other, with a matching variabel ( or more than one variable ). Sort both sets by the matching variable(s) then merge.

proc sort data=setone;

   by matchingvariable;

run;

proc sort data=settwo;

   by matchingvariable;

run;

data want;

   merge setone settwo;

   by matchingvariable;

run;

 

There may be some details on what you want done if there is no actual match.

View solution in original post


All Replies
Solution
‎04-25-2016 03:51 PM
Super User
Posts: 10,500

Re: How to do one to one merging in SAS

You may need to expand on what you are thinking about with one to one merge. Do mean first record in the first data set with the first record of the second set regardless OR by matching the value of a variable in each set?

 

The first is easy:

 

data want;

   merge setone settwo;

run;

 

The other, with a matching variabel ( or more than one variable ). Sort both sets by the matching variable(s) then merge.

proc sort data=setone;

   by matchingvariable;

run;

proc sort data=settwo;

   by matchingvariable;

run;

data want;

   merge setone settwo;

   by matchingvariable;

run;

 

There may be some details on what you want done if there is no actual match.

Regular Contributor
Posts: 159

Re: How to do one to one merging in SAS

[ Edited ]

I see ballardw's reply was marked as the solution.

Another answer is to use PROC SQL. In this way, you can use any valid SQL joins.

For example:

proc sql;
    create table newTable as
    select *
    from table1
    inner join table2
    on table1.ID = table2.ID;
quit;

 

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 321 views
  • 4 likes
  • 3 in conversation