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

Hello,

 

I have tried this function (https://support.sas.com/kb/40/934.html) but it seems that we are not able to 

get the create date.

 

Here's the macro :

 

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

Does someone know how to get the create date with the format monyy7. for a any file hosted on a
unix server. The modified date and the size works well but nothing show up for the create time


Regards,
alain

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Some filesystems used in Linux store a "birth time" (ext4 or btrfs come to mind), but that can be misleading, as it keeps the value the file was first written to the local filesystem. A copy across filesystems can result in a situation where the btime is past the modification and access time.

 

The fact that the operating system that powers the world has worked fine for decades without a creation date shows the technical irrelevance of such a timestamp, IMHO. If it is needed for the working of a certain application, that needs to be part of the file data, as what SAS does with their files.

 

Always keep in mind that most updates of a SAS dataset (e.g. PROC SORT) create a completely new file on the filesystem, and such is true for other applications (if I'm not completely wrong in my thinking, a docx or xlsx has to be rewritten completely, being a zipped archive).

 

To @alepage if your goal is to get that timestamp for SAS data, you can get it with PROC CONTENTS or from DICTIONARY.TABLES/SASHELP.VTABLE.

View solution in original post

4 REPLIES 4
Reeza
Super User
From that page:
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.

From a google search it seems to depend very much on the Unix flavour so I suspect you need to provide more details about your set up as well, specifically what type of unix and version.
Kurt_Bremser
Super User

Some filesystems used in Linux store a "birth time" (ext4 or btrfs come to mind), but that can be misleading, as it keeps the value the file was first written to the local filesystem. A copy across filesystems can result in a situation where the btime is past the modification and access time.

 

The fact that the operating system that powers the world has worked fine for decades without a creation date shows the technical irrelevance of such a timestamp, IMHO. If it is needed for the working of a certain application, that needs to be part of the file data, as what SAS does with their files.

 

Always keep in mind that most updates of a SAS dataset (e.g. PROC SORT) create a completely new file on the filesystem, and such is true for other applications (if I'm not completely wrong in my thinking, a docx or xlsx has to be rewritten completely, being a zipped archive).

 

To @alepage if your goal is to get that timestamp for SAS data, you can get it with PROC CONTENTS or from DICTIONARY.TABLES/SASHELP.VTABLE.

ballardw
Super User

I might try something like this:

data fileatt;
   length name $ 20 value $ 40;
   drop fid j infonum;
   fid=fopen("&filename.", "I");
   infonum=foptnum(fid);
   do j=1 to infonum;
      name=foptname(fid, j);
      value=finfo(fid, name);
      put 'File attribute' name 'has a value of ' value;
      output;
   end;
   fclose(fid);
run;

The data set, assuming no errors, should have a list of all the options you can request from your file system. The filename would have to have a full path.

TomKari
Onyx | Level 15

Here's a piece of code I've had for years, and about every six months I use it in a response on the communities.

It's way over designed for what you want, it pulls in all of the files in a directory, and then for each file picks up all of the attributes, but you should be able to see the necessary bits.

I just tried it, and it still works, but I have a Windows machine and no access to Unix. Give it a try. The only thing you should need to change is the directory on the first line.

Tom

 

/* Set the directory name to scan */
%let DirectoryName = C:\directory;

data DatasetsInADirectory;

   keep DirectoryAndDataset;
   length DatasetName DirectoryAndDataset $1024 FileRef $8;

   /* Assign the fileref */
   call missing(FileRef); /* Blank, so SAS will assign a file name */
   rc1 = filename(FileRef, "&DirectoryName."); /* Associate the file name with the directory */
   if rc1 ^= 0 then
      abort;

   /* Open the directory for access by SAS */
   DirectoryID = dopen(FileRef);
   if DirectoryID = 0 then
      abort;

   /* Get the count of directories and datasets */
   MemberCount = dnum(DirectoryID);
   if MemberCount = 0 then
      abort;

   /* Get all of the entry names ... directories and datasets */
   do MemberIndex = 1 to MemberCount;
      DatasetName = dread(DirectoryID, MemberIndex);
      if missing(DatasetName) then
         abort;

      DirectoryAndDataset = cats("&DirectoryName.","/",DatasetName);
      output;
   end;

   /* Close the directory */
   rc2 = dclose(DirectoryID);
   if rc2 ^= 0 then
      abort;
run;

data Attributes;

   keep DirectoryAndDataset OptionName OptionVal;
   length EntryType $12 FileRef $8 OptionName $20 OptionVal $1024;

   set DatasetsInADirectory;

   /* Assign the fileref */
   call missing(FileRef); /* Blank, so SAS will assign a file name */
   rc1 = filename(FileRef, DirectoryAndDataset); /* Associate the file name with the dataset or directory */
   if rc1 ^= 0 then
      abort;

   /* Open the entry for access by SAS. If it is a directory, zero will be returned */
   EntryID = fopen(FileRef);

   /* Process the entries */
   if EntryID = 0
   then do;
      EntryType = "Directory";
      output;
   end;

   else do;
      /* Get the number of options for the dataset */
      OptNum  = foptnum(EntryID); 
      if OptNum = . then
         abort;

         EntryType = "Dataset";

         /* Get all of the options for the dataset */
         do OptCount = 1 to OptNum;
            OptionName = foptname(EntryID, OptCount);
            OptionVal = finfo(EntryID, OptionName);
            output;
         end;
      
      /* Close the directory */
      rc2 = fclose(EntryID);
      if rc2 ^= 0 then
         abort;

   end;

run;

proc sql;
drop table DatasetsInADirectory;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 3308 views
  • 2 likes
  • 5 in conversation