/* 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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.