0

我在 SAS 中运行这个 sql 宏。

%macro calc(table=,cut=,whereclause=);
proc sql;
&table
   select 
        &cut as type format = $40. length = 40
       ,dt
       ,count(prod_nbr) as stat
       ,sum(new) as new
       ,sum(old) as old
       ,sum(retired) as retired
       ,sum(replaced) as replaced
       ,sum(final) as final
       ,sum(redo) as redo

from work.product
where retail_flg = 1
&whereclause
group by 1,2;
quit;
%mend calc;

我在程序中调用了大约 60 次宏,当我调用它时,它大约有 80% 的时间工作。但是每隔一段时间它就会产生这个错误: ERROR: All positional parameters must precede keyword parameters

如果我以相同的顺序运行代码,错误总是显示在同一行。但是,如果我开始以不同的顺序运行调用,错误最终会出现在调用宏的看似随机的代码行上。这是它被赶上的一个调用的例子(在计算表已经创建之后):

%calc(table = insert into calc, cut = 'Product', whereclause = and brand = 'JNJ' and Prod_type = 'N' and index(prod_nm, 'NEW') > 0);

我对这个错误特别困惑,因为我在宏中没有任何位置参数。我已经研究并解决了语法错误和其他常见问题,但无法解决错误。

4

1 回答 1

1

很可能你在某处有不平衡的报价。也许你有一些价值 WHERECLAUSE 有不平衡的报价。我会查看生成错误消息之前的值。这也可能是代码被截断的结果。例如,如果您将生成的代码写入文件,则某些长 WHERECLAUSE 值可能会被截断并导致引号不平衡。

在宏调用中添加一些额外的换行符可以更容易检查错误,因为较短的行更容易被人类扫描。

%calc
(table = insert into calc
,cut = 'Product'
,whereclause =
  and brand = 'JNJ' and Prod_type = 'N'
  and index(prod_nm, 'NEW') > 0
);
于 2017-03-20T21:02:33.113 回答