Wednesday, July 20, 2016

SAS: Data Step Merge example



Source:


* Merge example ;

data a;
input key1 key2 aonly both;
datalines;
1 1 1 1
1 2 2 2
3 1 3 3
3 2 6 6
5 1 5 5
;
run;


data b;
input key1 key2 bonly both;
datalines;
1 2 8 22  expect change var both from 2 to 22
3 3 8 3   expect insert
5 1 8 55  expect change var both from 5 to 55
;
run;


data merged;
merge a b;
by key1 key2;
run;


proc print data=merged;
run;



Results:


Obs
key1
key2
aonly
both
bonly
1
1
1
1
1
.
2
1
2
2
22
8
3
3
1
3
3
.
4
3
2
6
6
.
5
3
3
.
3
8
6
5
1
5
55
8

No comments:

Post a Comment