• Home
  • /
  • SAS PROGRAMS
  • /
  • Retrieve file size or last modified date of an external file

1 Comments

February 16, 2020

The FINFO functions return the value of a file specified. You can get six attributes named ‘info items’ through the use of the FINFO function.

filename fileref '/folders/myfolders/numerical.sas';                                                                                                          
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;
Retrieve file size or last modified date of an external file 1

To read multiple within a directory, the DOPEN, DNUM and DREAD functions can be used.

The DOPEN function is similar to the FOPEN function and it returns a directory identifier that allows the directory to be opened for input.

The DNUM function counts the number of files within the opened location. You can use this to loop through all the files in a location.

DREAD is used to read each file within the directory. This makes each file accessible for the FOPEN and FINFO functions.

data fileinfo(kepp=filename file moddate);
 filename files '/folders/myfolders';
 dirid=dopen('files');
 countfiles=dnum(dirid);
 do i=1 to countfiles;
  filename=dread(dirid, i);
  file='/folders/myfolders/'||filename;
  sysrc=filename('fnames', file);
  fid=fopen('fnames');

  if fid ^=0 then
   do;
    moddate=finfo(fid, 'Last Modified');
    output;
    sysrc=close(fid);
   end;
 end;
 rc=dclose(dirid);
run;
fopen

related posts:


Macro To check if a variable exists in SAS dataset


Generating Multiple Excel Files


Generating sum of rolling data Using the Lag function

Subhro Kar

About the author

Been in the realm with the professionals of the IT industry. I am passionate about Coding, Blogging, Web Designing and deliver creative and useful content for a wide array of audience.

Subhro

Leave a Reply

Your email address will not be published. Required fields are marked

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}