LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2003, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 31 Mar 2003 11:07:20 -0500
Reply-To:     diskin.dennis@KENDLE.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         diskin.dennis@KENDLE.COM
Subject:      Re: repeated code
Comments: To: Jean Roth <jroth@NBER.ORG>
Content-type: text/plain; charset=us-ascii

Jean,

Since this a macro, you need to somehow get the number of lags desired into a macro variable. I assume it is the same for all the input records. One way would be:

data _null_; set one; call symput('nlags',put(maxemer,3.)); stop; run;

followed by the previously specified datastep:

data one; set one; %lags(n=&nlags,var=stdsvc,out=svctyp) .... run;

HTH, Dennis Diskin

From: Jean Roth <jroth@NBER.ORG>@LISTSERV.UGA.EDU> on 03/31/2003 10:13 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: Re: repeated code

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 > > > > >


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