Date: Tue, 29 Jul 2008 23:59:30 +0000 Reply-To: toby dunn Sender: "SAS(r) Discussion" From: toby dunn Subject: Re: tip: Macro Design Checklist Comments: To: Bucher Scott In-Reply-To: <98634D42B37B2E4E96CF3A3BD3CD9AE602162722@EX1VS2.nyced.org> Content-Type: text/plain; charset="iso-8859-1" Scott , CountW and CountC is available in 9.1.3 Toby Dunn "Don't bail. The best gold is at the bottom of barrels of crap." Randy Pausch "Be prepared. Luck is where preparation meets opportunity." Randy Pausch > Date: Tue, 29 Jul 2008 11:07:21 -0400 > From: SBucher@SCHOOLS.NYC.GOV > Subject: Re: tip: Macro Design Checklist > To: SAS-L@LISTSERV.UGA.EDU > > Thanks. I think countW is new to 9.2, which I don't anticipate getting > it anytime soon. I am aware of the approach you present, but personally > I find %wordcount simpler to read and understand (which is as good a > reason to use a macro as any), especially when nesting loops like this. > Like the broader question of named v. positional parameter, use of the > '.' suffix, etc. at some point it boils down to context and taste. > > -Scott > > -----Original Message----- > From: data _null_, [mailto:datanull@gmail.com] > Sent: Tuesday, July 29, 2008 10:40 AM > To: Bucher Scott > Cc: SAS-L@listserv.uga.edu > Subject: Re: tip: Macro Design Checklist > > I thought you might say that, so only reason you counted the words was > to be about to write %DO I = 1 %TO (calculated value) which seem > pointless to me. > > Although nowadays I prefer to avoid this type of macro coding > altogether, it does have some utility. A little bit of restructuring > and you have code that does not rely on a macro you don't need. > > 1 %macro NotUsingWordsMacro(seasons=summer spring fall winter); > 2 %local i w; > 3 %let i = %eval(&i + 1); > 4 %let w = %scan(&seasons,&i,%str( )); > 5 %do %while(%superQ(w) ne); > 6 %PUT NOTE: Processing the &i.th word(&w); > 7 %let i = %eval(&i + 1); > 8 %let w = %scan(&seasons,&i,%str( )); > 9 %end; > 10 %put NOTE: It doesn%str(%')t really matter but the list has > %eval(&i-1) words; > 11 %mend notUsingWordsMacro; > 12 > 13 %notUsingWordsMacro; > NOTE: Processing the 1th word(summer) > NOTE: Processing the 2th word(spring) > NOTE: Processing the 3th word(fall) > NOTE: Processing the 4th word(winter) > NOTE: It doesn't really matter but the list has 4 words > > For the very rare case where the number of words is needed just code. > > %sysfunc(countW( > > > On 7/29/08, Bucher Scott wrote: >> For looping through a list of items, i.e.; >> >> %let seasons = summer spring fall winter; %do I = 1 %to >> %wordcount(&seasons); >> %let season = %scan(&seasons, &i); >> >> %end; >> >> >> -Scott >> >> -----Original Message----- >> From: data _null_, [mailto:datanull@gmail.com] >> Sent: Tuesday, July 29, 2008 10:05 AM >> To: Bucher Scott >> Cc: SAS-L@listserv.uga.edu >> Subject: Re: tip: Macro Design Checklist >> >> Why would you need a macro to count words? >> >> On 7/29/08, Bucher Scott wrote: >>> I use positional parameters with macro functions that I use >>> frequently >> >>> and that have arguments that are few and relatively intutitive, e.g. >>> %wordcount(). If the macro functions has more than 3 arguments, I >>> use a combination of positional parameters and keyword parameters >>> with default values. I think the examples cited within the sasautos >>> library >> >>> were also macro functions. >>> >>> Regards, >>> Scott Bucher >>> >>> >>> -----Original Message----- >>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > >>> Fehd, Ronald J. (CDC/CCHIS/NCPHI) >>> Sent: Tuesday, July 29, 2008 9:05 AM >>> To: SAS-L@LISTSERV.UGA.EDU >>> Subject: Re: tip: Macro Design Checklist >>> >>>> From: RolandRB >>>> >>>> On Jul 28, 10:06 pm, r...@CDC.GOV ("Fehd, Ronald J. (CDC/CCHIS/ >>>> NCPHI)") wrote: >>>>> I have updated my Macro Design Checklist page >>>>> >>>>> http://www.sascommunity.org/wiki/Macro_Design_Issues_Checklist >>>> >>>> Your first tip is "always use named parameters". >>> >>>> This is a bad general tip to give >>> >>> My 20 years experience says otherwise. >>> >>>> as it depends on the circumstances. >>> >>> imnsho, those circumstances are usually that the macro is in a >> program. >>> >>> \begin{quote} >>> Note: These recommendations are for project and site macros, i.e. >>> macros not in a program, but in separate files. >>> \end{quote} >>> >>>> The SAS Institute >>>> itself does not follow this recommendation. >>> >>> yes, I know. >>> From my perspective on the HelpDesk >>> SAS Institute creates more problems for itself and its customers by >>> publishing Reeeeally! Bad Examples both in OnLine Doc, paper >>> manuals, and training courses. >>> >>>> Check out the %trim and >>>> %left macros that they distribute with their sasautos library. >>> >>> There are 500 macros provided in 300 files in 13 folders in the >>> sasautos library. >>> The only thing that I would recommend about them is that they have a > >>> fairly consistent header for their documentation. >>> >>> Ron Fehd the documentation maven >>> and the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov >>> >> _________________________________________________________________ Stay in touch when you're away with Windows Live Messenger. http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_messenger2_072008 

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