I'm trying to calculate descriptive stats for a user. The macro takes the 'type' parameter. The type is a string which will be used in the code later.
%macro descriptive_stats(data, reqvar, type, filter);
proc means data = &data &type$;
var &reqvar;
by &filter;
run;
%mend descriptive_stats;
%descriptive_stats(test, &num_var, 'mean', fyear)
I'm getting the following error:
Syntax error, expecting one of the following: ;, (, ALPHA, CHARTYPE ...
I know why I'm getting the error. But I don't understand why the string 'mean' isn't being substituted.
Macro parameters don't have types. There is no 'numeric' or 'character' in macro parameters. They also shouldn't have quotes around them, unless the quotes are needed in the final code. Macro variables (and parameters) are just text substitution - so if you would type '
in the code then include it (or better yet, put "
around the parameter); otherwise don't.
%macro descriptive_stats(data, reqvar, type, filter);
proc means data = &data &type;
var &reqvar;
by &filter;
run;
%mend descriptive_stats;
%descriptive_stats(test, &num_var, mean, fyear)
I'm also not sure where the $
came from - that has no meaning in SAS in this context.