Here is a working custom macro "function" you can use to generate a list of variables ending in a suffix text pattern. It takes two parameters - the dataset name, and the suffix text:
%Macro EndsWith(DSN,Suffix);
%local dsid varlist rc whr lib ds;
/* Parameter Validation */
%if &suffix= %then %do;
%PUT ERROR: You must specify a suffix;
%GoTo EndMacro;
%end;
%if &DSN= %then %let DSN=&SYSLAST;
%let ds=%QSCAN(%QUPCASE(%SUPERQ(DSN)),2);
%if &ds= %then %do;
%let lib=WORK;
%let ds=%QUPCASE(%SUPERQ(DSN));
%end;
%else %let lib=%qscan(%QUPCASE(&DSN),1);
/* Get Variable Names */
%let whr=(WHERE=(LIBNAME="&lib" AND MEMNAME="&ds" AND UPCASE(NAME) like %STR(%')%nrstr(%%)%str(%QUPCASE(%SUPERQ(suffix))%')));
%let dsid=%sysfunc(open(sashelp.vcolumn&whr));
%if &dsid=0 %then %do;
%PUT ERROR: &DSN not opened;
%put ERROR- WHERE: &whr;
%PUT ERROR- &sysmsg;
%GoTo EndMacro;
%end;
%let rc=0;
%do %while (&rc=0);
%let rc=%sysfunc(fetch(&dsid));
%if &rc=0 %then %do;
%let varlist=&varlist %sysfunc(getvarc(&dsid,%sysfunc(varnum(&dsid,NAME))));
%end;
%end;
&varlist
%Endmacro:
%let rc=%sysfunc(close(&dsid));
%mend;
Here are some usage examples:
/*Write a list of the variables that end in 't' to the log:*/
%PUT NOTE: Variables are %EndsWith(sashelp.class,t);
/*Drop variables that end in 't' from the input dataset:*/
data test;
set sashelp.class(drop=%EndsWith(sashelp.class,t));
run;