BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buechler66
Barite | Level 11
Thanks so much for your time.
Kurt_Bremser
Super User

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.

Astounding
PROC Star

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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 5694 views
  • 6 likes
  • 5 in conversation