While we usually argue against the use of macros for some things, this is a perfect (even classic) case where a macro is precisely what is needed.
I'd have to do some research for the details, but that would rob you of the fun and learning.
Write a macro that uses dataset information functions to determine the names of the variables in a given dataset, then your could code
[pre]
DATA TEST;
MERGE ALPHA(IN=IN1 KEEP=A X Y Z)
BETA (IN=IN2 KEEP=A X Y Z %rename_vars(BETA));
BY A;
IF IN1;
X_DIF=X-X_Beta;
RUN;
[/pre]
Just for grins and giggles, have you considered using SQL to do this for you?
[pre]
proc sql;
create table test as
select a, x,y,z, (a.x - b.x) as x_dif, (a.y - b.y) as y_dif, (a.z - b.z) as z_dif
from ALPHA as a, BETA as b
where a.A = b.A;
quit;
[/pre]
This could be macroized as well, starting with
[pre]
%macro diffs(ALPHA, BETA, a, x, y, z);
proc sql;
create table test as
select &a, &x,&y,&z, (a.&x - b.&x) as &x._dif, (a.&y - b.&y) as &y._dif, (a.&z - b.&z) as &z._dif
from &ALPHA as a, &BETA as b
where a&a = b.&a;
quit;
%mend;
[/pre]
and it could be further generalized using the ???parm??? thingy for macros to allow for variable length parameter lists.