Expanding on Joe's last comment - is the column is in the same position, just called something different?
If so, you can use the dictionary.columns
table, selecting the specific column number, and storing the corresponding column name in a macro variable.
Example, your column is the 5th column in Excel/dataset...
/* Pull column name */
proc sql ;
select name into :DYNVAR
from dictionary.columns
where libname = 'SASHELP'
and memname = 'CLASS'
and varnum = 5 ;
quit ;
/* Then to reference the column simply substitute it for &DYNVAR */
data want ;
set sashelp.class (keep=&DYNVAR) ;
run ;
You could then extend this to multiple columns if necessary...
/* Pull column name */
proc sql ;
select name into :DYNVARS separated by ' '
from dictionary.columns
where libname = 'SASHELP'
and memname = 'CLASS'
and varnum in (1,4,5) ;
quit ;
/* Then to reference the columns simply substitute it for &DYNVARS */
data want ;
set sashelp.class (keep=&DYNVARS) ;
run ;