I need some code to all read log date/time stamps in a folder (or several folders) on a Unix system. I find plenty for Windows-based systems but not for Unix.
Do you need the "last modified" timestamps of files?
Yes the last date/time modified that is correct.
This is a code snippet I use to read the modification date from a directory listing.
Note that on a simple ls -l, you'll get the modification time for files less than 6 months old, or the year for older files in the same column. So my code replaces the time with the correct year.
You might need to adapt the column pointers in the input statement, this works with AIX.
The first part reads the listing into a temporary file and records messages from that in the SAS log.
filename oscmd pipe "ls -l &pathname > $HOME/files.lst 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
data filenames (keep=userid datum f_name);
infile '$HOME/files.lst';
length
userid $ 8
zzeit $ 5
monat $ 3
tag $ 2
f_name $ 100
;
format datum ddmmyyp10.;
input
@17 userid $8.
@46 monat
@50 tag
@53 zzeit $5.
@59 f_name
;
if substr(zzeit,3,1) = ':'
then do;
if monat in ('Jul','Aug','Sep','Oct','Nov','Dec')
then zzeit = put(year(&tagesdat)-1,z4.);
else zzeit = put(year(&tagesdat),z4.);
end;
mo = (index('JanFebMarAprMayJunJulAugSepOctNovDec',monat) + 2) / 3;
datum = input(substr(zzeit,1,4) !! put(mo,z2.) !! tag, yymmdd8.);
run;
If you need a scan through a whole directory tree, use the UNIX find command with the -ls directive and adapt the column pointers to the resulting format.
Kurt - code works ok - what is this macro variable
&tagesdat?
Ups, sorry, it's basically today(). You can safely replace it by this.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.