По пути похоже, что вы используете * nix. В этом случае вы можете получить последний файл, используя скрипт:
filename latest pipe "cd &Location_to1.; ls -t1 | egrep 'xlsx$' | head -n 1";
data _null_;
infile latest truncOver;
input fileName $200.;
call symput('latestFile', strip(fileName));
run;
Системно-независимое решение на основе Bruno_SAS код:
%macro getLatestFile(dirName=, extType=, out=);
%let extType = %upcase(&extType);
* Get the list of all files with the last modification date;
data allFiles;
length msg $ 256 fileRef $ 8 dirName $ 1024 fileName $ 256 fullName $ 1281;
rc_check=fileexist("&dirName");
if rc_check=0 then
do;
putlog "ERROR: &sysMacroname &dirName does not exist";
stop;
end;
rc_assign=fileName(fileRef, "&dirName");
dirId=dopen(fileRef);
if dirId=0 then
do;
msg=sysmsg();
putlog "ERROR: &sysMacroname could not open &dirName as directory";
putlog msg;
rc_assign=fileName(fileRef);
stop;
end;
n_files=dnum(dirId);
do i=1 to n_files;
fileName=dread(dirId, i);
if upcase(scan(fileName, -1, "."))="&extType" then
do;
dirName="&dirName";
fullName=catx("/", dirName, fileName);
n_match + 1;
rc_fnOpen=fileName('current', "&dirName" || fileName);
fileId=fOpen('current');
lastChanged=input(fInfo(fileId, 'Last Modified'), datetime.);
format lastChanged datetime.;
rc_close=fClose(fileId);
rc_fnClose=fileName('current');
output;
end;
end;
dirId=dclose(dirId);
rc_assign=fileName(fileRef);
msg=catx(" ", "NOTE: &sysMacroname found", n_match,
"files that match &extType");
putlog msg;
keep dirName fileName fullName lastChanged;
run;
* Keep only the latest file;
proc SQL outobs=1;
create table &out. as
select fullName
from allFiles
order by lastChanged desc
;
quit;
%mend;
%getLatestFile(dirName= %sysFunc(pathName(work)), extType=xlsx, out=latest);