If the dataset is large and creating a second copy of the dataset would be cumbersome then this is a more efficient way. However if you have duplicate results in your join you can run into issues.
*need to set space for it;
format empty_var $25.;
update have1 as a
set empty_var=(select b.name from sashelp.class as b where a.name=b.name);
merge dataset1 (in=a) dataset2 (in=b keep=var1 var2);
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.