BookmarkSubscribeRSS Feed
Pyrite | Level 9

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.

Pyrite | Level 9

Yes the last date/time modified that is correct.

Super User

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;
put _infile_;

data filenames (keep=userid datum f_name);
infile '$HOME/files.lst';
  userid $ 8
  zzeit $ 5
  monat $ 3
  tag $ 2
  f_name $ 100
format datum ddmmyyp10.;
  @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.);
mo = (index('JanFebMarAprMayJunJulAugSepOctNovDec',monat) + 2) / 3;
datum = input(substr(zzeit,1,4) !! put(mo,z2.) !! tag, yymmdd8.);

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.

Pyrite | Level 9

Kurt - code works ok - what is this macro variable



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1 like
  • 2 in conversation