| Date: | Wed, 25 Jun 2008 15:21:59 -0700 |
| Reply-To: | Peter <crawfordsoftware@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Peter <crawfordsoftware@GMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: Iteratively load macro |
|
| Content-Type: | text/plain; charset=ISO-8859-1 |
On Jun 25, 10:27 pm, mlhow...@avalon.net (Mary) wrote:
> Seeker,
>
> This is a little longer an approach but I like it because it is a bit =
> more general in that I can load up multiple parameters for each run into =
> a data set, then go get them in my macro; also calling a macro from a =
> data step, even a null data step, seems a little strange to me. =20
>
> -Mary
>
> %Macro run_macro(runnum);
>
> proc sql noprint;
>
> select param into :param
>
> from varset
>
> where obsnum=3D&runnum;
>
> %put ¶m;
>
> %Mend ;
>
> %Macro docalls;
>
> %Local I;
>
> proc sql noprint;
>
> select count(*) into :model_count
>
> from varset;
>
> quit;
>
> %Do I =3D 1 %To &model_count ;
>
> %run_macro(&i);
>
> %End ;
>
> %Mend docalls ;
>
> data varset;
>
> informat param $20.;
>
> infile cards;
>
> input param;
>
> obsnum + 1;
>
> cards;
>
> m10
>
> m20
>
> m35
>
> ;
>
> %docalls;
>
>
>
> ----- Original Message -----=20
> From: Chang Chung=20
> To: SA...@LISTSERV.UGA.EDU=20
> Sent: Wednesday, June 25, 2008 3:53 PM
> Subject: Re: Iteratively load macro
>
> On Wed, 25 Jun 2008 13:27:01 -0700, Seeker <zhongm...@GMAIL.COM> =
> wrote:
>
> >Howdy,
>
> >I had a macro %test(mn) and I want to run a bunch of times.
>
> >For example,
>
> >%test(m10);
> >%test(m20);
> >%test(m35);
>
> >The above code works fine. I composed a short loop but didn't work.
>
> >data _null_;
> >do mn=3D'm10','m20','m35';
> > %test(mn);
> >end;
>
> >Thanks!
>
> hi,
> i find the Ted Clay style, simple (but versatile) looping macro handy =
> in
> many situations. hth.
> cheers,
> chang
>
> /* substitute for your macro -- hope you know how to use %local! */
> /* if your macro uses mvars like i, item, or list but not declared */
> /* %local, then the %doOver will mal-function! */
> %macro test(mn);
> %put mn=3D&mn;
> %mend test;
>
> /* Ted Clay style pattern based list processing. this is */
> /* a bare bone implementation (by me) of Ted^s idea, */
> /* presented in the paper at SUGI 31, available at: */
> /* http://www2.sas.com/proceedings/sugi31/040-31.pdf */
> %macro doOver(list, phrase=3D?, between=3D%str( ));
> %local i item;
> %let i =3D 1;
> %let item =3D %scan(&list, &i);
> %do %while (&item^=3D);
> %*;%sysfunc(tranwrd(&phrase, ?, &item))
> %let i =3D %eval(&i + 1);
> %let item =3D %scan(&list, &i);
> %if (&item^=3D) %then %*;≬
> %end;
> %mend doOver;
>
> %doOver(m10 m20 m35, phrase=3D%nrstr(%test(?)))
> /* on log
> mn=3Dm10
> mn=3Dm20
> mn=3Dm35
> */- Hide quoted text -
>
> - Show quoted text -
just another way ... use %mLoopsX()
posted to SAS-L some time ago, a macro to support what you need,
like:
%mLoopsX( execut= test, with= m10 m20 m35 )
"a complete solution for macro looping"
Not only is it on SAS-L, it should also be available by searching in
www.lexjansen.com
%mLoopsX()
www2.sas.com/proceedings/sugi31/012-31.pdf
PeterC
|