Help using Base SAS procedures

Identifying when a file has been modified.

Posts: 42

Identifying when a file has been modified.

Good Afternoon All,

I have a file which sits in a folder on our server which is read only. This file is overidden monthly with new data from an external source. The date which this update is made is not consistant and therefore a batch job which runs on any specific date is impossible (well pointless).

What I originally wanted to do (without knowing the directory was read only) was to move the file to a new location on the day which it was updated, delete the initial file and run the rest of my code on the newly transfered data. The code for this was simple and worked like a charm. However, I discovered that the directory was read only and therefore my daily batch wants to pick it up everyday (as the file always exists).

I wondered if anyone knew a way of SAS identifying when a file had been modified, via the modified date.

Any help would be fantastic.

Super User
Posts: 5,254

Re: Identifying when a file has been modified.

This should've been a perfect task for the FINFO function. However, on 9.1.3/Solaris it has support only for File name, Owner name, Group name, Access Permission and File Size. If you have access to 9.2, try to run this code end see if something else pops up:

data info;
length infoname infoval $60;
*drop rc fid infonum i close;
do i=1 to infonum;

Otherwise, I guess you have to use os commands to retrieve the information you want. That can be done quite neatly by using the PIPE filename option.

Data never sleeps
Posts: 42

Re: Identifying when a file has been modified.

Thanks Linus.

Unfortunately I am presently stuck using 9.1.3.

I have attempted to use the following OS commands with no success:

Systask Command "Copy &ServerX.\pordata.tpt /y
&serverl.\Pordata&eom..tpt" Taskname = T01;
Waitfor T01;

Systask Command "Del &ServerX.\pordata.tpt" Taskname = T02;
Waitfor T02;


Systask Command "Move &ServerX.\pordata.tpt /y
&serverl.\Pordata&eom..tpt" Taskname = T01;
Waitfor T01;

Are there any other commands that I could use to get past my permissions issue?

Thank you.
Trusted Advisor
Posts: 2,113

Re: Identifying when a file has been modified.

This is a bit round-about, but you could run the DOS DIR command via the SAS X statement and pipe the results to a file that you can then read that to get the date on the file.

something like
x 'die&ServerX.\pordata.tpt > myfile.txt';

and then parse myfile.txt. You can probably simplify this by using the FILENAME statement with unnamed PIPEs.
Super Contributor
Super Contributor
Posts: 3,174

Re: Identifying when a file has been modified.

Along the same idea from Doc@Duke, the FILENAME supports the "pipe" engine to read/process a directory list. Check the SAS support website for additional references - here is one SUGI/SGF paper on the topic.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation