这是我的宏,下面。变量var1,var2,var3,VR和maxwt不输入到宏,也不在文件中。它们是在宏内部计算的中间结果。当我在SAS 9.3中执行时,我收到这样的消息:
1 var1 = &dcount1 * (&spop1/&refpr1)**2;
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
宏:
%macro confi (aart,dcount1,dcount2,dcount3,spop1,spop2,spop3,refpr1=0.53468238,refpr2=0.30153350,refpr3=0.16378412);
var1 = &dcount1 * (&spop1/&refpr1)**2;
var2 = &dcount1 * (&spop2/&refpr2)**2;
var3 = &dcount3 * (&spop1/&refpr3)**2;
VR = var1+var2+var3;
maxwt = max(&refpr1 &refpr2 &refpr3);
CI_low = (VR/ 2*&aart)) * cinv(0.025,2*(&aart**2)/VR);
CI_high = (( VR + maxwt**2) / (2*(&aart+maxwt)))* cinv(0.975, 2*(&aart+maxwt)**2/(VR + maxwt**2));
%put &aart CI_low CI_high;
%mend confi;
%confi (aart=1000, dcount1=20, dcount2=70, dcount3= 10. spop1=3000, spop2=3000, spop3=200);
答案 0 :(得分:1)
该宏必须在数据步骤内执行。这些是数据步骤变量和语句,不能在开放代码中执行。
您也无法将%put
用于此目的 - 您需要使用put
。
答案 1 :(得分:1)
试试这个:
Options Macrogen Symbolgen;
%macro confi (aart,dcount1,dcount2,dcount3,spop1,spop2,spop3,refpr1,refpr2,refpr3);
data _null_;
var1 = &dcount1 * (&spop1/&refpr1)**2;
var2 = &dcount1 * (&spop2/&refpr2)**2;
var3 = &dcount3 * (&spop1/&refpr3)**2;
VR = var1+var2+var3;
maxwt = max(&refpr1, &refpr2, &refpr3);
CI_low = (VR/ 2*&aart) * cinv(0.025,2*(&aart**2)/VR);
CI_high = (( VR + maxwt**2) / (2*(&aart+maxwt)))* cinv(0.975, 2*(&aart+maxwt)**2/(VR + maxwt**2));
put 'low =' CI_low;
put 'high = ' CI_high;
run;
%put &aart;
%mend confi;
%confi (aart=1000, dcount1=20, dcount2=70, dcount3= 10, spop1=3000, spop2=3000, spop3=200, refpr1=0.53468238, refpr2=0.30153350, refpr3=0.16378412)