|Date: ||Wed, 8 Jun 2005 20:46:41 +0000|
|Reply-To: ||toby dunn <tobydunn@HOTMAIL.COM>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||toby dunn <tobydunn@HOTMAIL.COM>|
|Subject: ||Re: Thee level by group "lag"|
|Content-Type: ||text/plain; format=flowed|
I would gladly do this problem the way you have ut set up with only my wits.
As your have your dataset up it is easy to do what you want with a lag or
retain statement. Could you give a better dataset that more closely
emulates your actual dataset.
As it stands now you only need to sort for insurance purposes and use the
From: Michael Murff <mjm33@MSM1.BYU.EDU>
Reply-To: Michael Murff <mjm33@MSM1.BYU.EDU>
Subject: Thee level by group "lag"
Date: Wed, 8 Jun 2005 14:23:33 -0600
Hi SAS L,
I have quarterly data that is organized within three by groups: id, year,
quarter. There are multiple instances of the same quarter but these records
have additional unique information (they are not duplicates). I am trying to
get information from the previous quarter within a given id. I need to copy
this forward in the spirit of a lag. So if I'm in 1990 q4 then I want the
value (if it exists) of DATE2 from 1989 q4 to be copied forward into a new
var called lastQ .
Obs ID DATE1 DATE2 year
1 00109210 02JUN1988 23JUN1989 1989 4
2 00109210 16NOV1988 23JUN1989 1989 4
3 00109210 28JUL1988 23JUN1989 1989 4
4 00109210 11JUL1988 23JUN1989 1989 4
5 00109210 02JUN1988 23JUN1989 1989 4
6 00109210 16AUG1988 23JUN1989 1989 4
7 00109210 23NOV1988 23JUN1989 1989 4
8 00109210 22MAR1989 23JUN1989 1989 4
9 00109210 16MAY1990 08AUG1991 1990 1
10 00109210 18APR1990 08AUG1991 1990 1
11 00109210 09APR1990 08AUG1991 1990 1
12 00109210 18JUL1990 08AUG1991 1990 1
I have tried this task the lag function in concert with first. and last.
flags and I don't believe lag() is well suited for this problem. Lag looks
to the previous record, where I want to look to the previous instance of the
inner-most by group (qtr) within an instance of the outermost by group (id).
I understand that retain can be used in place of lag. Any ideas would be
Many thanks in advance,
PS-I pity the job applicant that must do this on the hiring manager's laptop
during the interview with nothing but his wits.