システム日付またはファイル名の日付を使用して、最新のファイルを判別しますか? create of modified date を使用する場合は、foptname 関数を調べてそれらを決定してください。このコードは、ファイル名の日付を調べます。このコードは、X コマンドの承認を必要とせずに機能します。
data newestFile (keep=newestFile);
format newestFile $20.;
retain newestFile newestDate;
rc = filename("dir","z:\old\");
did = dopen("dir");
/* loop through file and subdirectories in a directory */
do i = 1 to dnum(did);
csvFile = dread(did,i);
rc=filename("fid",cats("z:\old\",csvFile));
sdid=dopen("fid");
/*check if date in name is newest if it is a file */
if sdid le 0 then do;
csvFileDate = input(substr(csvFile,6,6),ddmmyy6.);
if csvFileDate gt newestDate then do;
newestDate = csvFileDate;
newestFile = csvFile;
end;
end;
else rc = dclose(sdid);
end;
rc = dclose(did);
/* move and rename file with latest date to newestFile.csv */
rc = rename(cats("z:\old\",newestFile), "z:\new\newestFile.csv",'file');
run;