SAS : Join on Multiple Columns

Suppose you need to join two data sets (tables) based on multiple variables (columns) in SAS.

Step I : Creating two data sets (tables)
data def;
input a b $ d;
cards;
123 X 5
441 D 2
;
run;

data abc;
input a b $ c;
cards;
123 A 5
123 B 6
123 X 8
441 C 2
441 D 5
;
run;
Task : Suppose you need to join these two data sets (tables) based on variables a and b.

Step II : SQL Joins / Data Step Merge Statements
proc sql noprint;
create table xyz as
select * from
def x left join abc y
on x.a = y.a and x.b = y.b;
quit;
data xyz1;
merge def(in=x) abc(in=Y);
by a b;
if x;
run;
Output

Related Posts
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and Human Resource.

1 Response to "SAS : Join on Multiple Columns"

Next → ← Prev
Love this Post? Spread the Word!
Share