1

I am going to analyze a batch of SAS program file and I am stucked in getting the last modified time of program files. I have thought about X command but it was too inefficient.
I just find when I use infile statement:

data test;
  infile 'D:\test.txt' truncover;
  input ;
run;

Log shows the last modified time:

NOTE: The infile 'D:\test.txt' is:
      Filename=D:\test.txt,
      RECFM=V,LRECL=32767,File Size (bytes)=7,
      Last Modified=2021/1/26 15:25:48,
      Create Time=2021/1/26 15:25:42

As you can see, log window shows the infomation of file as a NOTE. However, my wish output is a variable filled with Last Modified Time.

Is there some option to get it while using infile statement? Surely, Other efficient ways are welcomed, too.

whymath
  • 1,262
  • 9
  • 16
  • What kind of analysis are you performing on the .sas files ? – Richard Jan 26 '21 at 13:27
  • @Richard Analyzing a SASor's programming style, like function using and proc using frequency and suspecting hard coding behavior. I think it will be useful to me and my colleague. – whymath Jan 27 '21 at 13:22
  • If you want to programmatically search for .sas files in a folder you will also want to use `DOPEN` then looping `DNUM` times fetching each filename with `DREAD` and cleaning up with `DCLOSE` post loop – Richard Jan 27 '21 at 13:52
  • @Richard Yes, I may try it later. I am now using an unamed pipe with system command and an infile statement, it allows me to get info of more than one folder at one time. – whymath Jan 28 '21 at 01:51

1 Answers1

2

Use functions FOPEN and FINFO

Example:

Show all available information items and their value for a sample data file.

filename datafile 'c:\temp\datafile.txt';

data _null_;
  file datafile;
  put 'Me data';
run;

data _null_;
  fid = fopen('datafile');

  if fid then do;
    do index = 1 to foptnum(fid);
      info_name = foptname(fid,index);
      info_value = finfo(fid, info_name);

      put index= info_name= @40 info_value=;       
    end;
    
    rc = fclose(fid);
  end;
run;

Will log information such as

index=1 info_name=Filename             info_value=c:\temp\datafile.txt
index=2 info_name=RECFM                info_value=V
index=3 info_name=LRECL                info_value=32767
index=4 info_name=File Size (bytes)    info_value=9
index=5 info_name=Last Modified        info_value=26Jan2021:06:29:47
index=6 info_name=Create Time          info_value=26Jan2021:06:28:23
Richard
  • 25,390
  • 3
  • 25
  • 38