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 (May 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 21 May 2004 08:26:47 -0400
Reply-To:     Ed Heaton <EdHeaton@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ed Heaton <EdHeaton@WESTAT.COM>
Subject:      Re: Scope of Macro Variables
Comments: To: Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Content-Type: text/plain

When I write a macro, I almost always include a parameter named debugging as follows:

%macro test( debugging=0 ) ;

%mEnd test ;

It does no harm even if it is not used. However, I can quickly implement its use with something like...

%macro test( debugging=0 ) ; /* Some code that creates a data set. */ Data foo ; Run ; %if &debugging %then %do ; Proc print data=foo( where=( ranUni(0) lt 0.05 ) ) ; Run ; %end ; %mEnd test ;

So, almost all of my macros have parameters!

Ed

Edward Heaton, SAS Senior Systems Analyst, Westat (An Employee-Owned Research Corporation), 1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195 Voice: (301) 610-4818 Fax: (301) 610-5128 mailto:EdHeaton@Westat.com http://www.Westat.com

-----Original Message----- From: Quentin McMullen [mailto:quentin_mcmullen@BROWN.EDU] Sent: Friday, May 21, 2004 7:32 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Scope of Macro Variables

On Thu, 20 May 2004 19:51:11 -0600, Jack Hamilton <JackHamilton@FIRSTHEALTH.COM> wrote:

>"Quentin McMullen" <quentin_mcmullen@BROWN.EDU> wrote: > >>Agree with Ron, that a macro without any parameters is a silly macro > >I disagree. I can think of two circumstances under which a macro >without parameters might be useful: > >1) A %MACRO SKIP ... %MEND SKIP macro whose only purpose is to skip >the execution of a block of SAS code.

Yup, I use this a lot during development. But I still count it as a silly macro. Because it's not really being used as a macro, and of course wastes time by actually compiling the code in between %macro and %mend. But there's always a good time for silliness. : )

>2) A macro whose behavior is controlled by other aspects of the >environment - for example, current system options or the name of the >current input file.

Fair enough. But I've found that even if I *think* a macro has no need for parameters when I write it, a month or so later I need to add parameters. So often I'll add a dummy parameter when I write it. This allows me to end all of my macro calls with close parenthesis. If you have macros with either no parameters or some parameters, then the calls to macros with no parameters must end with a white space character. Calls to macros with parameters will NOT end with a white space character, instead they may end with close parenthesis, or a macro statement boundary: %, *, 'proc' or 'data', semicolon, etc. Plus because the dummy parameter creates the local symbol table, (and I have occasionally forgotten to declare a variable local : ), I don't have to worry quite as much about being bitten by call symput's scoping limitations.

Kind Regards, --Quentin


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