Search code examples
sassas-macro

pass value of the dataset sas to a macro


i'm learning sas macro language but i have a problem i wrote a macro:

%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;

then what i want to do is launch a macro in another macro :

%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;

but i have this error:

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.

Is not possible use the macro in this way?? What is the right way to do what i want??? Thank you


Solution

  • Not sure why you want 2 macros to do this. Why not just a simple data step?

    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;