/* test datasets */
data one(drop=r) two(drop=z);
do until(x = 3);
input x z $ @@;
output one;
end;
input;
do until(x = 5);
input x r $ @@;
output two;
end;
stop;
cards;
1 A 2 B 3 C
1 R 2 S 3 T 4 W 5 G
;
run;
/* sort, merge, then output twice missing out either z or r */
proc sort data=one out=ones nodupkey;
by x;
run;
proc sort data=two out=twos nodupkey;
by x;
run;
data three;
merge ones(in=one) twos(in=two);
by x;
if one and two;
array temp(1) $1 _temporary_;
temp(1) = r;
call missing(r);
output;
r = temp(1);
call missing(z);
output;
run;
/* check */
proc print data=three noobs;
run;
/* on log
x z r
1 A
1 R
2 B
2 S
3 C
3 T
*/
Here is another solution which also accounts (like chang's) for different values for the key variable in both data sets not just in one:
Marius
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.