LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 19 Oct 2007 17:35:40 +0000
Reply-To:     Paul Dorfman <sashole@BELLSOUTH.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <sashole@BELLSOUTH.NET>
Organization: PDC
Subject:      Re: positional macro parameter as keyword
Comments: To: Guido T <cymraegerict@GMAIL.COM>

Guido,

It *is* useful, if only to bring to attention the often missed fact that in a macro call, a positional parameter can be used keyword-style (and not the other way around, of course). Thus to those maintaining that keyword parms are superior from the standpoint of code clarity, one could say that if a macro with positional parms is invoked keyword-style, there is no harm defining the parms as positional: since when one is trying to discern what the macro is doing, the macro call is viewed before the definition.

There are a few things in programming falling under the category always/never - for example, ubiquitous hard coding - because they make huge sense from the standpoint of defensive programming and help avoid lots of potential grief. Then there are things deemed to fall into this category just because some folks fail to fully understand how they work and, having been burned once or twice, resort to the always/never modus operandi masked behind the cover of defensive programming.

A typical representatives of this latter class are "never GOTO", "never couple LAG with IF", and, yes, "always use keyword parameters". Whilst it is generally a sound advice, there are still situations when positional parms may be personally preferable (even if only aesthetically) and work just as well.

Kind regards ------------ Paul Dorfman Jax, FL ------------

-------------- Original message ---------------------- From: Guido T <cymraegerict@GMAIL.COM> > > Hi, > > Something similar used to be in the "gotcha" test we did for SAS programmer > interviews. > > Given the following code ... > > %macro m(x); > %put &x.; > %mend; > > %m(a); > %m(x=b); > %m(x=b=c); > What would you expect to see in the log ... > > 1 %macro m(x); > 2 %put &x.; > 3 %mend; > 4 > 5 %m(a); > *a > *6 %m(x=b); > *b > *7 %m(x=b=c); > *b=c > * > Not a very useful test :) > > ++ Guido > > On 19/10/2007, ckxplus@yahoo.com <ckxplus@yahoo.com> wrote: > > > > It's more than 20 years ago since I wrote my first macro. But today I > > (inadvertently) discovered that you can refer to a positional > > parameter as a keyword, provided you use the right name. For example: > > > > %macro test(data); > > %put data=&data; > > %mend; > > > > %test(demo); > > %test(data=demo); > > > > This prints 'demo' to the log in both cases. Could be a useful feature > > sometimes. Am I the only one in the dark about this feature? > > > > John Hendrickx > >


Back to: Top of message | Previous page | Main SAS-L page