Date: Mon, 31 Mar 2003 10:13:20 -0500
Reply-To: Jean Roth <jroth@NBER.ORG>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jean Roth <jroth@NBER.ORG>
Subject: Re: repeated code
In-Reply-To: <OF0403CAB6.4A311D5A-ON85256CFA.00534974@kendle.com>
Content-Type: TEXT/PLAIN; charset=US-ASCII
Thanks! I neglected to mention that I would like
to loop until it reaches the value of a variable,
maxemer, which can range from 1 to 72.
On Mon, 31 Mar 2003 diskin.dennis@kendle.com wrote:
>
> Jean,
>
> Yes, easily:
>
> %macro lags(n=1,var=,out=);
> %local i;
> %do i = 1 %to &n;
> &out.&i = lag%eval(&i-1)(&var);
> %end;
> %mend;
>
> data one;
> set one;
> %lags(n=72,var=stdsvc,out=svctyp)
> ....
> run;
>
> HTH,
> Dennid Diskin
>
>
>
>
>
> From: Jean Roth <jroth@NBER.ORG>@LISTSERV.UGA.EDU> on 03/31/2003 09:44 AM
>
> Please respond to Jean Roth <jroth@NBER.ORG>
>
> Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
>
>
> To: SAS-L@LISTSERV.UGA.EDU
> cc:
>
> Subject: repeated code
>
>
> Hi Macro Mavens,
>
> I'd like to create a bunch of lag variables for a dataset
>
> data one;
> set one;
> svctyp1 = stdsvc;
> svctyp2 = lag1(stdsvc);
> ...
> svctyp72 = lag71(stdsvc);
>
>
>
> Can I do this without a line of code for each lag variable?
>
>
> Thanks,
>
> Jean Roth
> National Bureau of Economic Research
> http://www.nber.org/data
>
>
>
>
>
|