Keep in mind that the macro language knows only two scopes: global and local.
If you define macro B within macro A, variable X that is present in A will be in the local table of A, but not in the local table of B. If you now call execute a macro with single quotes, the execution of the macro is postponed and the expected variable will not be present.
Defining a macro within another macro only means that the inner macro is compiled every time the outer macro executes, creating unnecessary overhead. Nesting macro calls is a different thing and can make sense, but most of the time complex macro calling is unnecessary and a violation of the KISS principle that makes code hard to understand and brittle.
Based on some of your follow-up responses, here is an approach to consider.
proc sql;
select distinct(zip5) into : allzips separated by ' ' from sampledzips;
quit;
%macro loopthru;
%local i rule_order zip5;
%do i = 1 %to %sysfunc(countw(&allzips));
%let zip5 = %scan(&allzips, &i);
%do rule_order=1 %to 9;
%put &zip5 &rule_order;
%** Possibly do something else at this point as well;
%end;
%end;
%mend loopthru;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.