In reply to Jack Hamilton.

Thank you, Jack, for joining this discussion. While your proposed single data template per project approach ensures consistency of variables across different data tables, in my view, it can be practical only when your project uses just few variables. Otherwise, you would end up with having to list dozens of variables in the KEEP statement which by itself presents an “opportunity” for introducing errors (you may end up with correct variable attributes, but incorrect variable set.)

Besides, this leaves us without a way of knowing which variables belong to each dataset.

On the other hand, a “one data template per table” approach which I describe in this blog post, data template not only contains variable attributes, but it also defines a set of variables. That set of variables can be easily captured in a macro variable from the data template as in the following examples:

proc sql noprint;
select name into :varlist separated by ' '
from SASHELP.VCOLUMN
where libname='PARMSDL' and memname='DATATEMPLATE1';
quit;

or

proc sql noprint;
select name into :varlist separated by ' '
from DICTIONARY.COLUMNS
where libname='PARMSDL' and memname='DATATEMPLATE1';
quit;

Then you can use that macro variable in the KEEP statement along with data template injection:

data NEWDATA (keep=&varlist);
if 0 then set PARMSDL.DATATEMPLATE1;
set DATA;
/* ... */
run;

This will assure that only the variables from data template are kept while all other (interim) variables are dropped.