| Date: | Sun, 16 Oct 2011 07:04:43 -0400 |
| Reply-To: | Quentin McMullen <qmcmullen.sas@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Quentin McMullen <qmcmullen.sas@GMAIL.COM> |
| Subject: | Re: Lagging Groups |
|
| In-Reply-To: | <201110160549.p9G4Drfs018842@waikiki.cc.uga.edu> |
| Content-Type: | text/plain; charset=us-ascii |
Hi,
Looks like you are trying to lag by date also? Would something like below work? (untested)
Data want;
Set have;
By group date;
Retain Lagvara;
If first.date then do;
Lagvara=lag(vara);
If first.group then Lagvara=0;
End;
Run;
--Q.
On Oct 16, 2011, at 1:49 AM, Randy <randistan69@HOTMAIL.COM> wrote:
> Dear All:
> I need to lag the data set by groups. My data set is as follows:
>
> Date Group VarA
> 01OCT2011 1 1
> 01OCT2011 1 1
> 01OCT2011 1 1
> 02OCT2011 1 0
> 02OCT2011 1 0
> 01OCT2011 2 0
> 01OCT2011 2 0
> 02OCT2011 2 1
> 02OCT2011 2 1
> 02OCT2011 2 1
>
> The data that I need are as follows:
>
> Date Group VarA LagVarA
> 01OCT2011 1 1 0
> 01OCT2011 1 1 0
> 01OCT2011 1 1 0
> 02OCT2011 1 0 1
> 02OCT2011 1 0 1
> 01OCT2011 2 0 0
> 01OCT2011 2 0 0
> 02OCT2011 2 1 0
> 02OCT2011 2 1 0
> 02OCT2011 2 1 0
>
> Note: LagVARA on the first date of each group will always = 0. Please Help
>
> Randy
|