BookmarkSubscribeRSS Feed
Doug____
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.

5 REPLIES 5
Doug____
Pyrite | Level 9

Yes the last date/time modified that is correct.

Kurt_Bremser
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;
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.

Doug____
Pyrite | Level 9

Kurt - code works ok - what is this macro variable

&tagesdat?

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2385 views
  • 1 like
  • 2 in conversation