Date: Sat, 21 Feb 2004 12:25:10 -0500
Reply-To: Kerri Rivers <kerrir@PRB.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Kerri Rivers <kerrir@PRB.ORG>
Subject: Re: run a macro multiple times
Content-Type: text/plain; charset="iso-8859-1"
okay, i've got a basic question. i don't know why all of the percent signs
are needed within a macro program. what's the difference between:
%macro driver(maxno);
%do no = 1 %to &maxno;
%weight(&no)
%end;
%mend driver;
and this:
%macro driver(maxno);
do no = 1 to &maxno;
weight(&no)
end;
%mend driver;
i learned how to write macro programs from a book that i picked up at SAS in
maryland and i admit i didn't read the entire thing. i read until i knew
what i *thought* i needed to know. i must have missed something.
thanks for any info,
~kerri
-----Original Message-----
From: SAS(r) Discussion
To: SAS-L@LISTSERV.UGA.EDU
Sent: 2/20/2004 11:47 AM
Subject: Re: run a macro multiple times
Or even a bit more generalized:
%macro driver(maxno);
%do no = 1 %to &maxno;
%weight(&no)
%end;
%mend driver;
%driver(100)
I noticed you are using PROC APPEND. It may be appropriate and useful to
initialize the target dataset at the beginning of the outer macro.
On Fri, 20 Feb 2004 10:43:13 -0600, Toby Dunn <tdunn@OAKHILLTECH.COM>
wrote:
>Yes you can do this with a loop.
>
>Try this one on for size.
>
>%macro big_loop;
>
>%do iter = 1 %to 100;
> %weight(&i);
>%end;
>
>%mend big_loop;
>
>I have used this trick albeit I was needing to multiple nested loops.
But
>it works.
>
>HTH Toby Dunn
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Pat
>Moore
>Sent: Thursday, February 19, 2004 7:49 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: run a macro multiple times
>
>I have a macro:
>
>%macro weight (no);
>data w2003twin;
> set w2003;
> impw&no = imp&no;
> satw&no = imp&no;
>proc tabulate data=w2003twin exclnpwgt
> out=item&no
> (drop=_type_ _page_ _table_
> rename=(imp&no._mean=imp sat&no._mean=sat
> impw&no._mean=wimp satw&no._mean=wsat));
> var imp&no sat&no;
> var impw&no /weight=casewt;
> var satw&no /weight=casewt;
> table (imp&no='Unweighted Importance' impw&no ='Weighted
>Importance'
> sat&no='Unweighted Satisfaction' satw&no='Weighted
>Satisfaction')
> *mean=''*f=6.2, all='Mean'
> /rts=30 row=float Box=imp&no;
>run;
>proc append
> data=item&no
> out=item1;
>run;
>%mend weight;
>
>I want to run it 100 times. I know I could type:
>
>%weight (1);
>%weight (etc.);
>
>but I should be able to do this with some sort of loop.
>
>Any ideas?
>
>Pat Moore