Date: Thu, 16 Jun 2005 19:45:44 -0400
Reply-To: Lou <lpogodajr292185@COMCAST.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Lou <lpogodajr292185@COMCAST.NET>
Subject: Re: When to use Macro (was Things to ponder when you program)
"Richard Ristow" <wrristow@MINDSPRING.COM> wrote in message
> At 02:04 PM 6/15/2005, Dianne Rhodes wrote:
> > Toby Dunn wrote :
> >>Ian hasn't even written about this.
> >Certainly [Ian] has said that you shouldn't use macros until you are a
> >proficient programmer, and that macro should be used when you find
> >repetition in your code. In order to see the pattern, you usually
> >have to write the code first! Even when I know I want to make a
> >macro, I write SAS open code first, test it, make sure it works.
> Most of the discussion on when to use macros has been about
> 'encapsulating' macros, those that package a section of code for
> repeated use. There've been many caveats, quite rightly. Among others,
> macros are always harder to write and understand than the corresponding
> open code. And, for repeated use by others, macros require the same
> robustness of design and accuracy of documentation of any distributed
> code, usually several times as hard as making the code work reliably
> where it was first intended.
> It's worth mentioning the other uses for macros, which may justify
> writing a macro that's used as rarely as once.
> One is to create logic that executes steps repeatedly, or
> conditionally. I recall one that repeatedly executed some SQL code on a
> file of directional relations between cases, to implement the rule that
> if A>B and B>C, then A>C; it repeated until a step added no new
Well, maybe, but using an indexed dataset and the KEY option of the SET
statement would also get the whole chain. Personally, I think it's easier
to write and easier to understand. Also, easier to stop the action if the
chain is circular - what would that macro do if the file contained A>B, B>C,
C>A? But maybe that's just me.