/***************************************************************************************/
/* 指定LOG存放目录,程序统计该目录下所有LOG程序的运行时间 */
%let pathname=%str(D:\Downloads);
/********** 程序开始 **********/
options noxwait;
x "cd &pathname.";
x "dir *.log >dirfile";
filename dirfile "&pathname.\dirfile";
data lognamefile;
infile dirfile end=fend length=length;
length logname str $255;
input str $varying. length;
if length>40 and lowcase(substr(str,length-3,4))='.log' then do;
logname=substr(str,37,length-36);
keep logname;
output;
end;
run;
x "del dirfile";
%macro real_time();
%if %sysfunc(exist(pgm_real_time)) %then %do;
proc delete data=pgm_real_time;run;
%end;
%let dsid=%sysfunc(open(lognamefile));
%if &dsid>0 %then %do;
%let nobs=%sysfunc(attrn(&dsid,nobs));
%do i=1 %to &nobs;
%let rc=%sysfunc(fetchobs(&dsid,&i));
%let logname=%sysfunc(getvarc(&dsid,%sysfunc(varnum(&dsid,logname))));
%put 开始计算LOG程序运行时间:&logname;
filename logfile "&pathname.\&logname.";
data pgm_real_time_0;
infile logfile end=fend length=length;
length real_time cpu_time $20 log_name $100 data_step $10 str $255;
log_name="&logname.";
retain data_step real_time end_flag;
input str $varying. length;
if find(str,'NOTE: SAS 系统所用时间:','I') then do;
end_flag=1;
end;
if find(str,'实际时间','I') then do;
if end_flag ne 1 then do;
n+1;
data_step=compress("第"||put(n,z6.)||"步");
real_time=left(compress(str,'实际时间'));
end;
else do;
data_step="合计";
real_time=left(compress(str,'实际时间'));
end;
end;
if find(str,'CPU 时间','I') then do;
cpu_time=left(compress(str,'CPU 时间'));
output;
end;
drop n str end_flag;
run;
proc append base=pgm_real_time data=pgm_real_time_0;run;
proc delete data=pgm_real_time_0;run;
%end;
%end;
%let dsid=%sysfunc(close(&dsid));
%mend;
%real_time;
/********** 程序结束 **********/
在SAS应用班视频教学里面有很详细的程序解读。