SAS Macro in macro
up vote
2
down vote
favorite
I have one question regaring %macro.
Can I set %macro in another %macro?
Short example - "picture" of situation:
%macro Tier_1();
%do Iter = 1 to &i;
%macro Tier_2()
proc sql noprint;
select
1*&Iter into :var
from work._PRODSAVAIL
;quit;
%put &var;
%mend;
%Tier_2();
%end;
%mend;
%Tier_1();
sas sas-macro
add a comment |
up vote
2
down vote
favorite
I have one question regaring %macro.
Can I set %macro in another %macro?
Short example - "picture" of situation:
%macro Tier_1();
%do Iter = 1 to &i;
%macro Tier_2()
proc sql noprint;
select
1*&Iter into :var
from work._PRODSAVAIL
;quit;
%put &var;
%mend;
%Tier_2();
%end;
%mend;
%Tier_1();
sas sas-macro
2
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
1
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have one question regaring %macro.
Can I set %macro in another %macro?
Short example - "picture" of situation:
%macro Tier_1();
%do Iter = 1 to &i;
%macro Tier_2()
proc sql noprint;
select
1*&Iter into :var
from work._PRODSAVAIL
;quit;
%put &var;
%mend;
%Tier_2();
%end;
%mend;
%Tier_1();
sas sas-macro
I have one question regaring %macro.
Can I set %macro in another %macro?
Short example - "picture" of situation:
%macro Tier_1();
%do Iter = 1 to &i;
%macro Tier_2()
proc sql noprint;
select
1*&Iter into :var
from work._PRODSAVAIL
;quit;
%put &var;
%mend;
%Tier_2();
%end;
%mend;
%Tier_1();
sas sas-macro
sas sas-macro
edited Nov 10 at 8:18
asked Nov 9 at 18:29
DarkousPl
358
358
2
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
1
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14
add a comment |
2
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
1
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14
2
2
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
1
1
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but leave the call inside it.
%macro tier_1();
...
%Tier_2();
%mend tier_1();
%macro tier_2();
...
%mend tier_2;
%tier_1();
As you see above, you don't even have to order them in a particular way - as long as both are compiled before the execution of the macro it will work fine.
The only time it would make sense to put a macro definition inside another macro definition would be if the outer macro modified the inner macro in some way, and so it was necessary to re-compile the inner macro each time the outer macro executes.
While that's a theoretical use case, I don't think it's one you are likely to encounter in practice; there are lots of other ways to modify things without actually modifying the macro code itself, and as such it's considered poor programming style and should be avoided. You're adding (minimal, but some) overhead for no real benefit, and making it harder to understand the code.
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
add a comment |
up vote
2
down vote
The definitions are NOT logically nested. There is just a flat space of macro names. If you define the same %submacro
inside of %macroA
and %macroB
there will only be one %submacro
, which ever definition ran most recently.
You can nest macro CALLS (call a macro as part of a macro) but nesting the source code of the macro definitions is not a good idea. You can do it, but it will just confuse you.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but leave the call inside it.
%macro tier_1();
...
%Tier_2();
%mend tier_1();
%macro tier_2();
...
%mend tier_2;
%tier_1();
As you see above, you don't even have to order them in a particular way - as long as both are compiled before the execution of the macro it will work fine.
The only time it would make sense to put a macro definition inside another macro definition would be if the outer macro modified the inner macro in some way, and so it was necessary to re-compile the inner macro each time the outer macro executes.
While that's a theoretical use case, I don't think it's one you are likely to encounter in practice; there are lots of other ways to modify things without actually modifying the macro code itself, and as such it's considered poor programming style and should be avoided. You're adding (minimal, but some) overhead for no real benefit, and making it harder to understand the code.
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
add a comment |
up vote
3
down vote
accepted
The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but leave the call inside it.
%macro tier_1();
...
%Tier_2();
%mend tier_1();
%macro tier_2();
...
%mend tier_2;
%tier_1();
As you see above, you don't even have to order them in a particular way - as long as both are compiled before the execution of the macro it will work fine.
The only time it would make sense to put a macro definition inside another macro definition would be if the outer macro modified the inner macro in some way, and so it was necessary to re-compile the inner macro each time the outer macro executes.
While that's a theoretical use case, I don't think it's one you are likely to encounter in practice; there are lots of other ways to modify things without actually modifying the macro code itself, and as such it's considered poor programming style and should be avoided. You're adding (minimal, but some) overhead for no real benefit, and making it harder to understand the code.
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but leave the call inside it.
%macro tier_1();
...
%Tier_2();
%mend tier_1();
%macro tier_2();
...
%mend tier_2;
%tier_1();
As you see above, you don't even have to order them in a particular way - as long as both are compiled before the execution of the macro it will work fine.
The only time it would make sense to put a macro definition inside another macro definition would be if the outer macro modified the inner macro in some way, and so it was necessary to re-compile the inner macro each time the outer macro executes.
While that's a theoretical use case, I don't think it's one you are likely to encounter in practice; there are lots of other ways to modify things without actually modifying the macro code itself, and as such it's considered poor programming style and should be avoided. You're adding (minimal, but some) overhead for no real benefit, and making it harder to understand the code.
The answer to your question is "yes, it is possible." But it's poor style. The identical results from above will occur if you simply move the macro definition for %Tier_2 outside of macro Tier_1, but leave the call inside it.
%macro tier_1();
...
%Tier_2();
%mend tier_1();
%macro tier_2();
...
%mend tier_2;
%tier_1();
As you see above, you don't even have to order them in a particular way - as long as both are compiled before the execution of the macro it will work fine.
The only time it would make sense to put a macro definition inside another macro definition would be if the outer macro modified the inner macro in some way, and so it was necessary to re-compile the inner macro each time the outer macro executes.
While that's a theoretical use case, I don't think it's one you are likely to encounter in practice; there are lots of other ways to modify things without actually modifying the macro code itself, and as such it's considered poor programming style and should be avoided. You're adding (minimal, but some) overhead for no real benefit, and making it harder to understand the code.
answered Nov 9 at 19:40
Joe
55.2k53550
55.2k53550
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
add a comment |
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
Thanks all for your answer. Tommorow I will prepare and show my generally point of problem in my Application - mayby I haven't good way, idea how I can do solution my case.
– DarkousPl
Nov 9 at 19:46
add a comment |
up vote
2
down vote
The definitions are NOT logically nested. There is just a flat space of macro names. If you define the same %submacro
inside of %macroA
and %macroB
there will only be one %submacro
, which ever definition ran most recently.
You can nest macro CALLS (call a macro as part of a macro) but nesting the source code of the macro definitions is not a good idea. You can do it, but it will just confuse you.
add a comment |
up vote
2
down vote
The definitions are NOT logically nested. There is just a flat space of macro names. If you define the same %submacro
inside of %macroA
and %macroB
there will only be one %submacro
, which ever definition ran most recently.
You can nest macro CALLS (call a macro as part of a macro) but nesting the source code of the macro definitions is not a good idea. You can do it, but it will just confuse you.
add a comment |
up vote
2
down vote
up vote
2
down vote
The definitions are NOT logically nested. There is just a flat space of macro names. If you define the same %submacro
inside of %macroA
and %macroB
there will only be one %submacro
, which ever definition ran most recently.
You can nest macro CALLS (call a macro as part of a macro) but nesting the source code of the macro definitions is not a good idea. You can do it, but it will just confuse you.
The definitions are NOT logically nested. There is just a flat space of macro names. If you define the same %submacro
inside of %macroA
and %macroB
there will only be one %submacro
, which ever definition ran most recently.
You can nest macro CALLS (call a macro as part of a macro) but nesting the source code of the macro definitions is not a good idea. You can do it, but it will just confuse you.
edited Nov 9 at 18:49
answered Nov 9 at 18:38
Tom
21.7k2718
21.7k2718
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231450%2fsas-macro-in-macro%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You can - but you shouldn't.
– Reeza
Nov 9 at 19:06
1
Don't do it. Just don't.
– Robert Penridge
Nov 9 at 19:14