我正在使用%SYMEXIST来检查宏变量是否存在,然后根据结果继续或跳过。这听起来很简单,但SAS为我迄今为止尝试过的所有方法都犯了错误。
& num_tables是根据特定条件从数据集创建的宏。
proc sql noprint;
select distinct data_name into :num_tables separated by ' '
from TP_data
where trim(upcase(Data_Name)) in
(select distinct(trim(upcase(Data_Name))) from Check_table
where COALESCE(Num_Attri_DR,0)-COALESCE(Num_Attri_Data,0) = 0
and Name_Missing_Column eq ' ' and Var_Name eq ' ');
quit;
如果未解析或未创建此宏var(未从数据集中选择任何行),我想跳过。我用的时候,
%if %symexist(num_tables) %then %do;
SAS发出错误消息“MACRO变量名称X必须以字母或下划线开头”。所以我尝试使用以下所有方法删除前导空格:
%let num_tables = &num_tables; /* approach 1 */
%let num_tables = %sysfunc(trim(&num_tables)) /* approach 2 */
%let num_tables = %trim(&num_tables) /* approach 3 */
但这些都没有奏效。我仍然得到错误“MACRO变量名称X必须以字母或下划线开头”
答案 0 :(得分:0)
可能你正在为symexist中的num_tables添加一个&amp ;.这是以您要求的方式实现%SYMEXIST的正确方法。请注意,%symexist的参数不是&num_Tables
而是num_tables
(宏变量的实际名称)。如果您将&num_tables
与&
一起使用,%macro testshort(char=);
proc sql noprint;
select distinct name into :num_tables separated by ' '
from sashelp.class
where substr(name,1,1)="&char.";
quit;
%if %symexist(num_tables) %then %do;
%put Tables: &num_tables;
%end;
%mend testshort;
%testshort(char=A);
%testshort(char=B);
%testshort(char=Z);
会解决其内容。{/ 1}
{{1}}