BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hari6
Calcite | Level 5

Hi Team,

 

I am currently using SAS 9.4 and SAS Studio. My question would be on FINFO Function.

 

I am trying to get properties of a SAS file using FINFO function. I am able to get Bytes and Last Modified date of a SAS file however i am unable to get Date and Time of the SAS file created for the first time.

 

Could you let me know is there any other way or any function that we have in SAS to get a file created date and time.

 

Below is my code and using the same code i am trying to get SAS file created Date and Time.

/** 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;

Capture1.JPGCapture.JPG

 

Thanks,

Hari

1 ACCEPTED SOLUTION
5 REPLIES 5
Hari6
Calcite | Level 5

@Kurt_Bremser Thank you so much for your response.

pdhokriya
Pyrite | Level 9
If UNIX doesnt support then is there any other way to get create date info?
Kurt_Bremser
Super User

@pdhokriya wrote:
If UNIX doesnt support then is there any other way to get create date info?

Only for files where the respective application keeps such a timestamp within the file (or a metadata repository).

For instance, SAS provides CRDATE in DICTIONARY.TABLES.

andreas_lds
Jade | Level 19

There is an example program in the documentation of finfo, showing the names of all options:

data _null_;
   length opt $100 optval $100;
   /* Allocate file  */
   rc=FILENAME('myfile', "C:\aaa.txt");
   /* Open file */
   fid=FOPEN('myfile');
   /* Get number of information
      items */
   infocnt=FOPTNUM(fid);
   /* Retrieve information items
      and print to log */
   put @1 "Information for a &SysScp. System Services File:";
   do j=1 to infocnt;
      opt=FOPTNAME(fid,j);
      optval=FINFO(fid,upcase(opt));
      put @1 opt @20 optval;
   end;
   /* Close the file */
   rc=FCLOSE(fid);
   /* Deallocate the file */
   rc=FILENAME('myfile');
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5510 views
  • 1 like
  • 4 in conversation