Date: Tue, 29 Jul 2008 09:40:25 -0500 Reply-To: "data _null_," Sender: "SAS(r) Discussion" From: "data _null_," Subject: Re: tip: Macro Design Checklist Comments: To: Bucher Scott In-Reply-To: <98634D42B37B2E4E96CF3A3BD3CD9AE6021626C1@EX1VS2.nyced.org> Content-Type: text/plain; charset=ISO-8859-1 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 > > > 

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