OPTIONS PS=MAX LS=MAX NOCENTER SASMSTORE=SASUSER MSTORED MAUTOSOURCE;
/*获取指定文件夹的指定类型的所有文件*/
%MACRO GET_NAME(DIRNAME,TYP,OUT_TABLE)/STORE;/*参数有两个:路径,文件类型后缀*/
%PUT %STR(———–>DIRNAME=&DIRNAME) ;
%PUT %STR(———–>TYP=&TYP) ;
DATA TEMP;
RC=FILENAME(“DIR”,”&DIRNAME”);/*把&DIRNAME值传给文件引用符“DIR”*/
OPENFILE=DOPEN(“DIR”);/*得到路径标示符OPENFILE,DOPEN是打开directory的sas内置函数*/
IF OPENFILE>0 THEN DO;/*如果OPENFILE>0表示正确打开路径*/
NUMMEM=DNUM(OPENFILE);/*得到路径标示符OPENFILE中member的个数nummem*/
DO II=1 TO NUMMEM;
NAME=DREAD(OPENFILE,II);/*用DREAD依次读取每个文件的名字到NAME*/
filepath=”&DIRNAME”||NAME;
fnum=compress(NAME,”.xml”,””);
fnum=compress(fnum,”user_case”,””);
OUTPUT;/*依次输出*/
END;
END;
KEEP NAME filepath fnum;/*只保留filepath、fnum列*/
RUN;
PROC SORT DATA=TEMP;/*按照NAME排序*/
BY DESCENDING NAME;
%IF &TYP^=ALL %THEN %DO;/*是否过滤特定的文件类型&TYP*/
WHERE INDEX(UPCASE(NAME),UPCASE(“.&TYP”));/*Y,则通过检索NAME是否包含&TYP的方式过滤文件类型*/
%END;
RUN;
DATA &OUT_TABLE(KEEP=NAME ID DIRECTORY);
LENGTH DIRECTORY $20.;
SET TEMP;
ID=_N_;
DIRECTORY=”&DIRNAME.”;
RUN;
PROC APPEND BASE=S.DIR DATA=&OUT_TABLE;
RUN;
RUN;
%MEND;
LIBNAME S ‘.’;
%MACRO GETALL;
DATA _NULL_;
DO I=’报告样例及指标说明’,’数据字典’;
CALL EXECUTE(CATS(‘%GET_NAME(.\’||I||’,xlsx,DIR)’));
END;
DO I=’报告样例PDF版’;
CALL EXECUTE(CATS(‘%GET_NAME(.\’||I||’,pdf,DIR)’));
END;
**%GET_NAME(.\白皮书,pdf,DIR);
/*参数1:log文件所在位置
参数2:读取文件类型
参数3:log文件名存储的数据集名称*/
%MEND;
%GETALL;
ODS HTML FILE=’.\目录.xls’;
PROC PRINT DATA=S.DIR;
RUN;
ODS HTML CLOSE;