/* 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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: