过去用proc sql查SASHELP.VCOLUMN表格,但是在9.3中发现速度比较慢
于是改用proc contents了,然后速度就比较快了,我也不知道这两个差在哪
望高手指教
- %macro ChkVar(SourceTable,InputVar,FlagVarExists);
- /**********************************************************************/
- /* 此宏的作用是检查某数据表中是否存在指定的变量。其中,SourceTable是 */
- /* 原始表格;InputVar是指定的变量,若为多个变量,请用空格分隔;Flag_ */
- /* VarExists是标记宏变量名称,=1表示变量存在,否则=0,若有多个InputVar*/
- /* 变量,则不同位置上的1或0代表相应的变量是否存在。 */
- /* */
- /* 最终得到的是宏变量&FlagVarExists,若该数据表包含指定变量,则 */
- /* &FlagVarExists=1,否则=0,若为多个变量,则不同位置上的1或0代表相应 */
- /* 的变量是否存在。 */
- /* */
- /* Created on 2012.4.27 */
- /* Modified on 2012.9.18 */
- /**********************************************************************/
- %if %SYSFUNC(FIND(&SourceTable,.)) NE 0 %then %do;
- %let CV_LibName=%UPCASE(%SCAN(&SourceTable,1,.));
- %let CV_MemName=%UPCASE(%SCAN(&SourceTable,2,.));
- %end;
- %else %do;
- %let CV_LibName=WORK;
- %let CV_MemName=%UPCASE(&SourceTable);
- %end;
- %ChkDataSet(DataSet=&CV_LibName..&CV_MemName,FlagDataSetExists=CV_FlagDataSetExists);
- %if &CV_FlagDataSetExists EQ 1 %then %do;
- proc contents data=&SourceTable out=CV_temp(keep=name) noprint;
- run;
- %global &FlagVarExists;
- %if %SYSFUNC(FIND(&InputVar,%STR( ))) NE 0 %then %do;
- %SeparateString(InputString=&InputVar,OutputString=CV);
- %do CV_i=1 %to &CV_Num;
- %let CV_FlagVarExists&CV_i=0;
- data _null_;
- set CV_temp;
- call symputx("CV_FlagVarExists&CV_i",'1');
- where UPCASE(name)=UPCASE("&&CV_Var&CV_i.");
- run;
- %end;
- %let &FlagVarExists=&&CV_FlagVarExists1;
- %do CV_j=2 %to &CV_Num;
- %let &FlagVarExists=&&&FlagVarExists.&&CV_FlagVarExists&CV_j;
- %end;
- %end;
- %else %do;
- %let &FlagVarExists=0;
- data _null_;
- set CV_temp;
- call symputx("&FlagVarExists",'1');
- where UPCASE(name)=UPCASE("&InputVar.");
- run;
- %end;
- %end;
- %else %if &CV_FlagDataSetExists EQ 0 %then %do;
- %put ERROR: The DataSet &SourceTable does not exist, please check it again.;
- %goto exit;
- %end;
- %else %do;
- %put ERROR: There may be something wrong with the macro ChkDataSet, please contact the writer for help.;
- %goto exit;
- %end;
- /* 若要显示&FlagVarExists的值,请取消下面的注释 */
- /*%put &FlagVarExists=&&&FlagVarExists;*/
- /* 删除不必要的表格 */
- proc delete data=CV_temp;
- run;
- %exit:
- %mend;
- %macro Demo();
- %let SourceTable=Allretoffund_holding_temp1;
- %let InputVar=End_Yr End_Mt End_Dy End_Qt;
- %let FlagVarExists=FlagVarExists1;
- %ChkVar(&SourceTable,&InputVar,&FlagVarExists);
- %let InputVar=End_Yr End_Mt End_Dy;
- %let FlagVarExists=FlagVarExists2;
- %ChkVar(&SourceTable,&InputVar,&FlagVarExists);
- %mend;