下面是用於將文件屬性拉入日誌的代碼。要從字符轉換爲數字的文件屬性值
參考代碼:http://support.sas.com/kb/40/934.html
%macro FileAttribs(filename);
%global rc fid fidc;
%global 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;
data DSN ;
length CreateDT_ ModifyDT_ $200. ;
/*Path of the file along with the file extension*/
%FileAttribs (C:\Derived\GRSL.log) ;
/*Creation date of the file*/
CreateDT_ = "&CreateDT" ;
/*Modification date of the file*/
ModifyDT_ = "&ModifyDT" ;
run;
我複製宏變量的值到SAS變量。宏變量保存的是不可接受的日期和時間格式SAS9.2。我想將CreateDT_和ModifyDT_轉換爲數字。我試圖通過手動轉換搜索與SUBSTR函數的字符串。有沒有辦法動態處理它,而無需手動搜索日期月份,年份和時間的字符串。有沒有辦法控制文件屬性格式,例如上面的程序返回2017年3月01日05:22:30點在幾次運行和其他幾次日期01 MAR 2017 05:22:30。日期格式不斷變化。
編輯我的文章。 &root只是我用於文件路徑的一個宏變量。 –