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!
Please show the code you used to actually CALL the macro.
Please show the SAS code you want it to produce for that call.
Do you even need a macro to do what you want?
Couldn't you just do it all with one PROC MEANS call?
proc means data=&data n nmiss min max mean median q1 q3;
ways 1;
class &cat;
var &cont ;
run;
Please show the code you used to actually CALL the macro.
Please show the SAS code you want it to produce for that call.
Do you even need a macro to do what you want?
Couldn't you just do it all with one PROC MEANS call?
proc means data=&data n nmiss min max mean median q1 q3;
ways 1;
class &cat;
var &cont ;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.