Prev: Intentionally specifying an unclosed %DO loop in a macro XXXX
Next: comparing individual and groups in datasets in the same
From: Arthur Tabachneck on 13 Feb 2010 15:13 Dan, What kind of task are you trying to accomplish? You can always build-in conditional logic to exit a do loop. Art --------- On Sat, 13 Feb 2010 15:00:34 -0500, Dan Abner <dan.abner99(a)GMAIL.COM> wrote: >Hello, > >I want to do something like the following. Is there a way around the error >in macro compilation when an unclosed %DO exists with a macro? > >%MACRO M1; >%DO I = 1 %TO &N; >DATA D2; > SET D1; > WHERE CLASS = &I; >RUN; >%MEND; > >%MACRO ALL; >%M1 %M2 %END; >%M1 %M3 %END; >%MEND; > >where %M2 %M3 are previously defined (however, code omitted here). > >In other words, is there a way to close a %DO loop outside of the original >nested macro that the loop began?
From: Jack Hamilton on 13 Feb 2010 15:12 You might be able to do something tricky with macro quoting, but no one will be able to understand it later unless you put a lot of work into the documentation. Why do you want to do this? What can you do that can't be done in a more conventional way? -- Jack Hamilton jfh(a)alumni.stanford.org Caelum non animum mutant qui trans mare currunt. On Feb 13, 2010, at 12:00 pm, Dan Abner wrote: > Hello, > > I want to do something like the following. Is there a way around the error > in macro compilation when an unclosed %DO exists with a macro? > > %MACRO M1; > %DO I = 1 %TO &N; > DATA D2; > SET D1; > WHERE CLASS = &I; > RUN; > %MEND; > > %MACRO ALL; > %M1 %M2 %END; > %M1 %M3 %END; > %MEND; > > where %M2 %M3 are previously defined (however, code omitted here). > > In other words, is there a way to close a %DO loop outside of the original > nested macro that the loop began?
From: "Data _null_;" on 13 Feb 2010 16:21 I don't think you can compile the %DO with out the %END and AFIK the %DO has to be compiled. I think you can accomplish what you want with a parameter for M1. HOWEVER, there may be a much easier more straight forward way to accomplish the same task. data d1; do class=1 to 2; output; end; run; %MACRO M1(n=,xmac=); %DO I = 1 %TO &N; DATA D2; SET D1; WHERE CLASS = &I; RUN; %unquote(%&xmac); %end; %MEND; %macro m2; %put NOTE: This could get ugly.; %mend; %macro m3; %put WARNING: Help I%str(%')m stuck in a mire of percent signs and ampersands.; %mend; %MACRO ALL; %M1(n=1,xmac=M2) %M1(n=2,xmac=M3) %MEND; options mprint=0; %all; run; On 2/13/10, Dan Abner <dan.abner99(a)gmail.com> wrote: > Hello, > > I want to do something like the following. Is there a way around the error > in macro compilation when an unclosed %DO exists with a macro? > > %MACRO M1; > %DO I = 1 %TO &N; > DATA D2; > SET D1; > WHERE CLASS = &I; > RUN; > %MEND; > > %MACRO ALL; > %M1 %M2 %END; > %M1 %M3 %END; > %MEND; > > where %M2 %M3 are previously defined (however, code omitted here). > > In other words, is there a way to close a %DO loop outside of the original > nested macro that the loop began? >
From: montura on 16 Feb 2010 09:42
If you are trying to generate blocks of unfinished SAS code that can then be submitted as a collection during a later step, you can only do that with SCL submit blocks. stage #1 - Begin the DO block. submit; if anyCondition then do; endsubmit; stage #99 - You are done generating code, finish the DO block. submit; end; endsubmit; stage #3 - you are done, submit all generated code for execution. submit continue; endsubmit; |