DATA Step, Macro, Functions and more

Read Log Date/Time Stamps

Reply
Contributor
Posts: 27

Read Log Date/Time Stamps

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.

Super User
Posts: 6,962

Re: Read Log Date/Time Stamps

Do you need the "last modified" timestamps of files?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 27

Re: Read Log Date/Time Stamps

Yes the last date/time modified that is correct.

Super User
Posts: 6,962

Re: Read Log Date/Time Stamps

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 27

Re: Read Log Date/Time Stamps

Kurt - code works ok - what is this macro variable

&tagesdat?

 

Super User
Posts: 6,962

Re: Read Log Date/Time Stamps

Ups, sorry, it's basically today(). You can safely replace it by this.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 5 replies
  • 137 views
  • 1 like
  • 2 in conversation