You can filter either the filenames dataset (avoids modifying the macro) or in the macro (which would be more efficient).
For clarity, I'd recommend modifying the filenames dataset, unless you have a particularly large directory..
data new:
set filenames;
if substr(fname,1,3)='abc' and scan(fname,2,'.')='txt';
run;
alternatively, to modify the macro:
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=fname);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
fname=dread(handle,i);
/* custom filter */
if substr(fname,1,3)='abc' and scan(fname,2,'.')='txt' then output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;