尝试在 SAS 中获取文件属性(文件大小、创建日期时间和上次修改日期时间)

Trying to get file attributes (file size , create date time and last modified date time) in SAS

我正在使用以下宏通过 SAS 获取 Linux 文件属性。我正在获取大小和上次修改时间的值,但没有获取 "Create Date Time".

的任何值
%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=%sysfunc(finfo(&fid,Create Time));
   %let ModifyDT=%sysfunc(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;

%FileAttribs(/path/test.csv);

我不知道我错过了什么。 除了大小、创建和修改日期之外,我们还可以获得任何其他文件属性吗?

谢谢, Sampath.

有关可用内容的列表,您可以查看 SAS Documentation for FINFO in Unix. That isn't updated for the additions you note above, which are listed here,但它们应该有效。

您的宏在 Windows 中为我检索了所有三个信息位,尽管这当然可能与 Linux/Unix 不同。 Windows 文档确实列出了三个新项目 - 所以我想知道它们在 Unix/Linux 中是否存在问题并且它们在 9.3 中没有得到完全支持。 (它们仍然没有在 9.4 文档中列出,如果相关的话。)

根据这个答案,许多 Linux 系统不存储文件创建日期(或者即使存储了文件创建日期,也无法使用标准名称访问):https://unix.stackexchange.com/questions/91197/how-to-find-creation-date-of-file .

如果您想通过 FINFO() 获取所有可用的文件属性的值,您可以使用 FOPTNUM() 来查找可用属性的数量,然后循环遍历它们。这是一个宏:

%macro GetAllAttributes(file);

  %local rc fref fid i AttributeName AttributeValue;

  %let rc=%sysfunc(filename(fref,&file));
  %let fid=%sysfunc(fopen(&fref));

  %do i=1 %to %sysfunc(foptnum(&fid));
    %let AttributeName=%sysfunc(foptname(&fid,&i));
    %let AttributeValue=%sysfunc(finfo(&fid,&AttributeName));
    %put &AttributeName : &AttributeValue;
  %end;

  %let fid=%sysfunc(fclose(&fid));
  %let rc=%sysfunc(filename(fref));

%mend GetAllAttributes;

在 Windows (SAS 9.3) 上我得到:

78   %GetAllAttributes(d:\junk\somefile.txt)
Filename : d:\junk\somefile.txt
RECFM : V
LRECL : 256
File Size (bytes) : 1011
Last Modified : 06Dec2013:14:14:54
Create Time : 06Dec2013:14:14:52

在 Linux (SAS 9.3) 上我得到:

41         %GetAllAttributes(~/somefile.txt)    
Filename : /home/Quentin/somefile.txt
Owner Name : Quentin
Group Name : somegroup
Access Permission : rwx------
Last Modified : Fri Dec  6 14:14:54 2013
File Size (bytes) : 1011

最后,请注意 SAS 9.3 在 Linux returns 上以丑陋的格式修改日期。技术支持告诉我 9.4 returns 是一种像 Windows 这样的 SAS 友好日期时间格式。如果您使用的是 9.3,请参阅此问题以获取有关解析日期的建议:.