Date: Fri, 27 Jul 2007 14:37:42 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: macro variable based on do loop control variable
On Fri, 27 Jul 2007 17:09:16 -0000, hoxiea <hoxiea@GMAIL.COM> wrote:
>Hello, everyone! Just a quick question for you all on macro
>variables; I appreciate your assistance and thank you in advance for
>your help.
>
>Working inside of a macro, I'd like to process some data sets using a
>do loop. I'd also like to have a variable within the do loop that's
>based on the value of the control variable. Specifically, I'd like
>the loop control variable to run from 1 to 11, and the inside variable
>to run from 2 to 12, each incrementing by 1 each time through the
>loop. In my mistaken brain, the code looks something like this:
>
>%do i=1 %to 11;
> %let j=&i+1;
>
>data both;
> merge code_per&i._replicates code_per&j._replicates;
>
>However, the log file gives me an error, with the following message:
>NOTE: Line generated by the macro variable "J".
>186 code_per1+1_replicates
>
>How can I get SAS to read this as code_per2_replicates instead?
...
Hi, Hoxie,
%let j = %eval(&i + 1); will do, like below.
Cheers,
Chang
%macro loop;
%local i j;
%do i = 1 %to 11;
%let j = %eval(&i + 1);
%put i=&i j=&j;
%end;
%mend loop;
%loop
/* on log
i=1 j=2
i=2 j=3
i=3 j=4
i=4 j=5
i=5 j=6
i=6 j=7
i=7 j=8
i=8 j=9
i=9 j=10
i=10 j=11
i=11 j=12
*/
|