Charles,
I'd recommend an SQL solution as easier to code. Consider this code:
**********************************************************************;
/*Create two data sets to play with*/
data DS1;
LENGTH Text $1 Num 8 DS1 $1;
DS1="X";
do Text= "A","B","C";
do Num=1 to 2;
output;
end;
end;
run;
data DS2;
LENGTH Text $1 Num 8 DS2 $1;
DS2="X";
do Text= "A","C";
do Num=1 to 5;
output;
end;
end;
run;
/* SQL solution */
proc sql;
create table Merged_sql as
select coalesce(A.TEXT,B.TEXT,"") AS Text
, coalesce(a.Num,B.Num) as Num
, DS1
, DS2
from ds1 as a
full JOIN
ds2 as b
on a.Text=b.Text and a.Num=b.num
;
quit;
**********************************************************************;
You can produce the same results with the following data step code & concatenating variables:
**********************************************************************;
/*Data Step Solution*/
data DS1a;
set DS1;
_joinvar=CATX(Text,Num);
run;
proc sort data=DS1a;
by _joinvar;
run;
data DS2a;
set DS2;
_joinvar=CATX(Text,Num);
run;
proc sort data=DS2a;
by _joinvar;
run;
data Merged_data_step;
merge DS1a
DS2a ;
by _joinvar;
drop _joinvar;
run;
proc sort data=merged_data_step;
by Text Num;
run;
**********************************************************************;
Hope this helps!