Working on a macro function to return the modified date of a file as a SAS date, that will run on Linux (SAS 9.3). I want to avoid using OS commands (e.g. piping the results of an LS command) as code needs to work in an environment with NOXCMD. Below is a first draft (no error handling code, etc), using finfo().
Was disappointed by the format of the date returned by finfo(), e.g."Fri Apr 10 14:54:10 2015". Then was more disappointed by my inability to input() this string without the ugly parsing below. I have generally avoided using ANYDTDTE informat in the past, out of fear that it does too much guessing and doesn't throw errors. But it feels like overkill to write a custom date-time informat to handle this string.
Would appreciate thoughts on better ways to convert the date string to a SAS date, better ways to get the file modified date, and any pitfalls to below.
%macro GetModDate(file);
%*Get the modified date of a linux file, as SAS date;
%local rc fref fid ModDate;
%let rc=%sysfunc(filename(fref,&file));
%let fid=%sysfunc(fopen(&fref));
%let ModDate=%sysfunc(finfo(&fid,Last Modified));
%*Linux Last Modified returns format like: Fri Apr 10 14:54:10 2015;
%let ModDate=%sysfunc(inputn(%scan(&moddate,2,%str( )) %scan(&moddate,3,%str( )) %scan(&moddate,5,%str( ))
,anydtdte11
));
%let fid=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(fref));
&ModDate
%mend GetModDate;