Here is my code. I hope this could help you. %macro rename_files(path=); data a; r=filename("fir","&path."); d=dopen("fir"); if d>0 then do; n=dnum(d); do i=1 to n; fname=dread(d,i); if find(fname,".txt")>0 then do; output; end; end; end; c=dclose(d); keep fname; run; proc sql noprint; select count(*) into :n from a ; select fname into: fnames separated by "*" from a ; quit; %do i=1 %to &n.; %let fname=%scan(&fnames.,&i.,*); %let new_fname=%scan(&fname,1,_); %put &fname.; data _null_; rc=rename("&path.\&fname.","&path.\&new_fname..txt", 'file'); run; %end; %mend rename_files;
... View more