Date: Wed, 5 May 2004 09:06:00 -0400
Reply-To: Steve Raimi <steven.raimi@GM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Steve Raimi <steven.raimi@GM.COM>
Subject: Re: problem with macro
On Wed, 5 May 2004 03:26:51 -0400, Mayukh Dass <dass@UGA.EDU> wrote:
>Thanks a lot. My idea on macro was not clear, but I was able to fix it.
>I have another question. When do we use %if %then in a macro?
>Thanks.
>Mayukh
Mayukh,
In your original example, you always want to generate the code if flag in
('1', '2'...etc., because it's part of the data step work you want to do on
every iteration of the macro. Therefore, a %if (macro conditional) is not
appropriate.
Use %if %then within a macro to decide whether or not to produce SAS
code. Suppose your code was intended to make the work.one dataset have
output based on a different value of the flag variable. In that case, you
could do a %if (macro conditional) to select the if (non-macro) statement
to include in each iteration of the code.
I find it useful to think of the macro facility as an assistant SAS
programmer - I tell it which code it should write.
HTH,
Steve Raimi
|