BookmarkSubscribeRSS Feed
syam_india_kochi
Calcite | Level 5
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..
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Patrick
Opal | Level 21
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
Peter_C
Rhodochrosite | Level 12
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
Ksharp
Super User
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
syam_india_kochi
Calcite | Level 5
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..
Peter_C
Rhodochrosite | Level 12
try anydtdtm informat
Otherwise you have to recombine it into a style easier for the datetime. informat
Ksharp
Super User
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 7 replies
  • 4832 views
  • 0 likes
  • 5 in conversation