The following code is changing all the .TXT files under a fold into .SAS files.
%let path_in= D:\temp\02_table ; *the pathname for txt files;
%let path_out= D:\temp\02_table ; *the pathname for sas files;
filename x pipe "dir &path_in.\*.txt /s /b";
data x;
infile x truncover;
input old $2000.;
new=cats(prxchange('s/\w+$//',1,strip(old)),'sas');
rc=rename(strip(old),strip(new),'file');
run;
And an alternative code by using sas capability: (especially your file name is utf8 encoding)
/******For UTF-8 编码的文件名***********/
%let path_in= D:\temp\02_table ; *the pathname for txt files;
%let path_out= D:\temp\02_table ; *the pathname for sas files;
data _null_;
length fname old new $ 200;
rc=filename('x',"&path_in.");
did=dopen('x');
do i=1 to dnum(did);
fname=dread(did,i);
if lowcase(strip(scan(fname,-1,'.')))='txt' then do;
old=cats("&path_in",'\',fname);
new=cats(prxchange('s/\w+$//',1,strip(old)),'sas');
rc=rename(strip(old),strip(new),'file');
end;
end;
run;
... View more