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();









share|improve this question



















  • 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














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();









share|improve this question



















  • 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












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();









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












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.






share|improve this answer




















  • 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

















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.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    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.






    share|improve this answer




















    • 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














    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.






    share|improve this answer




















    • 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












    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.






    share|improve this answer












    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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
















    • 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












    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.






    share|improve this answer


























      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.






      share|improve this answer
























        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 18:49

























        answered Nov 9 at 18:38









        Tom

        21.7k2718




        21.7k2718



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20