以下代码实现功能:
1、获取10个模型分别使用哪些变量
2、变量所模型使用的次数
3、把上表格输出到EXCEL中
%INCLUDE '00@HEADER.SAS';
%let dir=..\04@Model;
libname cc "&dir";
PROC FORMAT;
VALUE UseFmt
1='使用'
0='未使用'
OTHER='其它'
;
RUN;
PROC DATASETS LIBRARY=S NODETAILS NOLIST;
DELETE ModelVariableList VarFreq;
RUN;
%MACRO FreqAppend(DSIN,FN);
PROC FREQ DATA=&DSIN;
TABLES &FN/MISSING NOPRINT OUT=A;
RUN;
DATA B;
LENGTH FName $32. VAL $200.;
SET A;
VAL=&FN.;
FName="&FN.";
DROP &FN.;
RUN;
PROC APPEND BASE=S.VarFreq DATA=B;
RUN;
%MEND;
%MACRO ModelVariable;
%DO SM=0 %TO 99;
DATA A;
LENGTH ModelOrder $3.;
SET CC.model_params&SM;
ModelOrder="&SM.";
RUN;
PROC APPEND BASE=S.ModelVariableList DATA=A;
RUN;
%END;
DATA S.ModelVariableList;
SET S.ModelVariableList;
ARRAY NUM{*} _NUMERIC_;
DO I=1 TO DIM(NUM);
IF MISSING(NUM{I}) THEN NUM{I}=0;
ELSE NUM{I}=1;
END;
KEEP ModelOrder X1_WOE X2_WOE X3_WOE X4_WOE X5_WOE B1_WOE S1_WOE;
RUN;
%MEND;
%ModelVariable;
DATA _NULL_;
DO V='X1_WOE','X2_WOE','X3_WOE','X4_WOE','X5_WOE','B1_WOE','S1_WOE';
CALL EXECUTE('%FreqAppend(S.ModelVariableList,'||V||')');
END;
RUN;
PROC PRINT DATA=S.VarFreq;
RUN;
PROC SORT DATA=S.VarFreq OUT=A1(DROP=PERCENT);
BY FName;
RUN;
PROC TRANSPOSE DATA=A1 OUT=A2(DROP=_NAME_);
BY FName;
RUN;
DATA A2;
SET A2;
IF MISSING(COL2) THEN COL2=0;
RUN;
ODS TAGSETS.EXCELXP FILE='ModelVariableList.XLSX';
PROC PRINT DATA=S.ModelVariableList LABEL;
VAR ModelOrder X1_WOE X2_WOE X3_WOE X4_WOE X5_WOE B1_WOE S1_WOE;
FORMAT X1_WOE X2_WOE X3_WOE X4_WOE X5_WOE B1_WOE S1_WOE UseFmt.;
LABEL ModelOrder='模型号';
RUN;
PROC SORT DATA=A2;
BY DESCENDING COL1;
RUN;
PROC PRINT DATA=A2 LABEL;
LABEL FName='变量' COL1='进入模型次数' COL2='未进入模型次数';
VAR FName COL1 COL2;
RUN;
ODS TAGSETS.EXCELXP CLOSE;