Did you intend to post this to the SAS/IML Support Community?
I assume the data sets all have the same number of observations and they are all ordered the same way so that the i_th observation of each data set is related to the i_th of the other data sets. If so, what you are doing is fine.
You can do the analysis in a single call: rename the variables, merge the data sets into one, and then call PROC CORR. The resulting correlation matrix is a block matrix. The block diagonal elements represent the correlations within each data set. The off-diagonal block represent correlations between data sets.
If you use PROC IML, you can just horizontally concatenate the data and take the correlation. You don't even need to rename the variables:
proc iml;
use D1;
read all var _NUM_ into X[colname=varNames];
close D1;
DSNames = {D2 D3 D4};
do i = 1 to ncol(DSNames);
use (DSNames);
read all var _NUM_ into D[colname=v];
close (DSNames);
X = X || D;
varNames = varNames || v;
end;
C = corr(X);
print C[c=varNames r=varNames];
