Hi,
I'm new at macro writing and trying out what I thought should be an easy one. The purpose of the macro is to check that the categorical variables I created from continuous variables are set correctly. This is my code:
%macro check(data=, Cat=, Cont=);
%let total_cat_vars = %sysfunc(countw(&Cat));
%let total_cont_vars = %sysfunc(countw(&Cont));
%do i = 1 %to &total_cat_vars;
%let selected_cat_var = %scan(&Cat, &i);
proc sort data=&data;
by &selected_cat_var;
run;
%do j = 1 %to &total_cont_vars;
%let selected_cont_var = %scan(&Cont, &j);
proc means data=&data n nmiss min max mean median q1 q3;
var &selected_cont_var;
by &selected_cat_var;
run;
%end;
%end;
%mend;
The problem is that it is running proc means for all of my continuous variables by each of my categorical variables (ie. I want only peso_nac to be ran with low_bw, but not sdg_nac). This can be seen here in the log with the mprint option:

I am not sure how to modify this macro to fix this. Any input is appreciated, thank you!