[英]pass value of the dataset sas to a macro
我正在学习sas宏语言,但有一个问题我写了一个宏:
%macro avg_acceleration(mark_type, avg_acceleration, mark_angle);
%if &mark_type='A' %then %sysfunc(abs(&avg_acceleration/%sysfunc(cos(%sysfunc(abs(&mark_angle*( 3.1415926535897/180.0)))))));
%else %if &mark_type='C' %then %sysfunc(abs(&avg_acceleration/%sysfunc(sin(%sysfunc(abs(&mark_angle*( 3.1415926535897/180.0)))))));
%mend avg_acceleration;
然后我想做的是在另一个宏中启动一个宏:
%macro statistiche;
data pippo;
set prova;
a = mark_type;
b= avg_acceleration;
c = mark_angle;
avg_acc=%avg_acceleration(a, b, c);
run;
%mend statistiche;
%statistiche;
但是我有这个错误:
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT.
这样无法使用宏吗? 什么是做我想要的正确方法? 谢谢
不知道为什么要2个宏来执行此操作。 为什么不只是一个简单的数据步骤?
data work.test;
set work.prova;
if mark_type='A' then do;
avg_acc=abs(avg_acceleration)/(cos(abs(mark_angle)*(constant('pi')/180.0)));
end;
if mark_type='C' then do;
avg_acc=abs(avg_acceleration)/(sin(abs(mark_angle)*(constant('pi')/180.0)));
end;
run;
重复数据较少的替代数据步骤:
data work.test;
set work.prova;
select (mark_type);
when('A') phase = 0;
when('C') phase = 90;
end;
avg_acc=abs(avg_acceleration)/cos((mark_angle + phase)*constant('pi')/180.0);
run;
如果您想捕获此逻辑以便在其他数据步骤中重用,并且可以选择使用不同的数据集变量来代替原始变量,则可以执行以下操作:
%macro avg_acceleration(mark_type =mark_type,
avg_acceleration =avg_acceleration,
mark_angle =mark_angle,
avg_acc =avg_acc
);
select (&mark_type);
when('A') phase = 0;
when('C') phase = 90;
end;
&avg_acc=abs(&avg_acceleration)/cos((&mark_angle + phase)*constant('pi')/180.0);
%mend;
然后,您应该可以像您最初预期的那样调用它或更少它:
data work.test;
set work.prova;
%avg_acceleration;
run;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.