/* 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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.