DATA Step, Macro, Functions and more

last modified date of the imported file

Reply
Occasional Contributor
Posts: 15

last modified date of the imported file

Hi All,

Hi I have automated a process, and I was interested to know whether it is possible to get the last modified date of the file(txt,xls..etc) which is imported..

My problem or rather intention is to validate the file which is getting imported. I mean, I am importing a file from the Server(remote), which is supposed to be replaced or modified everyday by my user. At times it happens that user may not replace the file at the specified time(usually 1 hr prior to sceduled stream), if that is the case I would like to check that the file which is getting imported is a modified file or not by looking at the modified date.

Alternatives like telling the business user to give a different name with date..etc are not feasible due to some internal issues.

please put your thoughts in..
Super Contributor
Super Contributor
Posts: 3,174

Re: last modified date of the imported file

Posted in reply to syam_india_kochi
Yes, investigate using the SAS FINFO CALL function. The SAS support website has SAS-hosted documentation and supplemental technical reference material showing examples - as well, you may want to search the archives.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

last modified date site:sas.com
Respected Advisor
Posts: 4,173

Re: last modified date of the imported file

Posted in reply to syam_india_kochi
Hi

Lookup functin FINFO() in the SAS doc.

You'll find this example code which is all you need to get started:
data info;
length infoname infoval $60;
drop rc fid infonum i close;
rc=filename('abc','physical-filename');
fid=fopen('abc');
infonum=foptnum(fid);
do i=1 to infonum;
infoname=foptname(fid,i);
infoval=finfo(fid,infoname);
output;
end;
close=fclose(fid);
run;

Be aware that also other processes like disk backup/restore or a compress could change a create or modified date.

An alternative to FINFO would be to directly execute a OS command and then capture the result (i.e. using "filename pipe ...").

HTH
Patrick Message was edited by: Patrick
Valued Guide
Posts: 2,177

Re: last modified date of the imported file

If not already on SAS 9.2 this will encourage your upgrade somewhat. Before 9.2 the file date is not available through FINFO. Then it was a lot more op.sys- and release-specific to extract the dates.
I'm trying to encourage SAS to provide these pieces of external file information in a simple way through infile options or PROC import. Already some of this is reported to the SAS log or a macro variable like &dbsysmsg and variants. More could be done for the external files we read with SAS.
imho
add your voice through the sasware ballot

peterC
Super User
Posts: 10,018

Re: last modified date of the imported file

Posted in reply to syam_india_kochi
Hi.
You can use Filename and PIPE to get the modified date of the file in the directionary.
ls -l for UNIX, dir for WIN.


Ksharp
Occasional Contributor
Posts: 15

Re: last modified date of the imported file

Thanks a tone folks..I did it with FINFO...But the last modified date was coming in an un usual format
eg:for 03Dec2010 1:36PM it was showing
3 Dec Fri 13:36:00 2010

Any suggestions to convert it into a date so that I can do some logical operations..
Valued Guide
Posts: 2,177

Re: last modified date of the imported file

Posted in reply to syam_india_kochi
try anydtdtm informat
Otherwise you have to recombine it into a style easier for the datetime. informat
Super User
Posts: 10,018

Re: last modified date of the imported file

Posted in reply to syam_india_kochi
Hi.
I think FILENAME + PIPE is just more simple.
It can easily get the modifed date of file.


[pre]
filename date pipe 'dir c:\temp\ /a';
data temp(keep=date time file_name);
infile date length=len;
input whole $varying200. len;
date=scan(whole,1,' ');
time=scan(whole,2,' ');
size=scan(whole,3,' ');
file_name=scan(whole,4,' ');
if findc(file_name,'.') and file_name not in ('.' '..') then output;
run;
proc print;run;
[/pre]



Ksharp
Ask a Question
Discussion stats
  • 7 replies
  • 2125 views
  • 0 likes
  • 5 in conversation