data set3;
merge dataset1 (in=a) dataset2 (in=b keep=var1 var2);
by var1;
if a;
run;
This will make a new data set (never overwrite your original data set when testing out code!) by merging your first and second data sets by your common variable. If dataset1 has var1's that aren't in dataset2, then set3.var2 will be empty. But where dataset1's var1 equals dataset2's var1, then set3.var2 will be the same as dataset2.var2.
However, if you need dataset2's var1's that aren't also in dataset1, then this won't work because it will only bring in those where the var1 is in common.