我在SAS中運行這個sql宏。如何用SAS宏解決關鍵字錯誤
%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;
我在程序中調用宏約六十次,當我調用它時,它大約有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);
我特別受錯誤很困惑,因爲我沒有任何位置參數宏。我已經研究過並解決了語法錯誤和其他常見問題而無法解決錯誤。
你怎麼多次調用它?通過其他一些宏?呼叫執行? – Tom
我只是運行上面的代碼的多行代碼。例如: %calc(表格= insert into calc,cut ='Product',where條款=和品牌='JNJ'); %calc(table = insert into calc,cut ='New Produce',whereclause = and brand ='WMT'and Prod_type ='Q'); – Jarom
那你是用手打字的? – Tom