Hello.
You can try this code
%macro dirclear(dir=d:\test,ext=xls);
%let ext=%upcase(&ext);
%let dlm=\;
%let filrf=;
%let rc=%sysfunc(filename(filrf,"&dir"));
%let did=%sysfunc(dopen(&filrf));
%let lstname=;
%let memcount=%sysfunc(dnum(&did));
%if &memcount > 0 %then %do;
%do i=1 %to &memcount;
%let lstname=%sysfunc(dread(&did,&i));
%let file=&dir&dlm&lstname;
%let ln=%length(&lstname);
data _null_;
c="&lstname"; c1=reverse(c); ln1=index(c1,'.'); ln=&ln-ln1+2; ln3=ln1-1;
ln4=upcase(substr(c,ln,ln3));
call symput('ln2',trim(left(ln4)));
run;
%if &ln2=&ext or &ext= %then %do;
%let rb=%sysfunc(filename(fname,"&file"));
%let rv=%sysfunc(fdelete(&fname));
%end; %end; %end;
%let rc=%sysfunc(dclose(&did));
%mend dirclear;
%let path=%sysfunc(pathname(mylib));
%dirclear(dir=&path,ext=png)