Usage Note 40934: Retrieve file size, create time, and last modified date of an external file
Starting in SAS® 9.2, there are three additional attributes for the FINFO function. They are:
File Size(bytes)
Create Time
Last Modified
The sample code on the Full Code tab illustrates how to use the FINFO function within a macro to retrieve the values of these new attributes.
A non-macro technique is illustrated on the Full Code tab as well.
The create date is not stored with a file on UNIX. Therefore, the CRDATE variable that is within the code on the Full Code tab is missing on UNIX.
Operating System and Release Information
SAS System | Base SAS | 64-bit Enabled AIX | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 TS1M0 | |
Windows Vista | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
z/OS 64-bit | 9.2 TS1M0 | |
z/OS | 9.2 TS1M0 | |
64-bit Enabled HP-UX | 9.2 TS1M0 | |
64-bit Enabled Solaris | 9.2 TS1M0 | |
HP-UX IPF | 9.2 TS1M0 | |
Linux | 9.2 TS1M0 | |
Linux for x64 | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 TS1M0 | |
Solaris for x64 | 9.2 TS1M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
/** Macro technique **/
%macro FileAttribs(filename);
%local rc fid fidc;
%local Bytes CreateDT ModifyDT;
%let rc=%sysfunc(filename(onefile,&filename));
%let fid=%sysfunc(fopen(&onefile));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%let CreateDT=%qsysfunc(finfo(&fid,Create Time));
%let ModifyDT=%qsysfunc(finfo(&fid,Last Modified));
%let fidc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(onefile));
%put NOTE: File size of &filename is &Bytes bytes;
%put NOTE- Created &CreateDT;
%put NOTE- Last modified &ModifyDT;
%mend FileAttribs;
/** Just pass in the path and file name **/
%FileAttribs(c:\aaa.txt)
/** Non-macro technique **/
filename fileref 'c:\aaa.txt';
data a(drop=fid);
infile fileref truncover obs=1;
fid=fopen('fileref');
Bytes=finfo(fid,'File Size (bytes)');
crdate=finfo(fid,'Create Time');
moddate=finfo(fid,'Last Modified');
run;
proc print;
run;
The following is printed to the SAS log:
NOTE: File size of c:\aaa.txt is 5 bytes
Created 02Jul2010:08:15:24
Last modified 21Jul2010:16:03:20
Using new attributes for the FINFO function to retrieve file size, create time, and last modified date.
Date Modified: | 2013-07-05 15:50:04 |
Date Created: | 2010-09-17 11:18:11 |