Date: Tue, 14 Dec 2004 05:00:42 -0800
Reply-To: Dennis Diskin <diskin@SNET.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dennis Diskin <diskin@SNET.NET>
Subject: Re: how to retain last year's information if missing??
Content-Type: text/plain; charset=us-ascii
xzhou,
I didn't read what you wanted carefully enough and I think I got it backwards. You can get the result you asked for from this code by first sorting on firm_id and DESCENDING year. Then run the datastep without the year in the BY statement.
Regards,
Dennis Diskin
Dennis Diskin <diskin@snet.net> wrote:xzhou,
Try this:
data new(drop=_year1 _year2);
set old (rename=year=_year2);
by firm_id year;
retain _year1;
if first.firm_id then _year1 = _year2 - 1;
do year = _year1 +1 to _year2;
output;
end;
_year1 = _year2;
run;
HTH,
Dennis Diskin
xzhou80@HOTMAIL.COM wrote:
I was wondering whether you have some 'smart' codes doing the
following: :)
Basically, what I want is to eliminate missing observations for some
years of the firms because I know they exists, by coping the previous
year's info to this year's.
original data set:
firm_Id year x
1004 1990 13
1004 1991 12
1004 1992 9
1004 1993 9
1004 1994 10
1004 1995 10
1004 1996 10 **
1004 2000 9
1011 1990 7
1011 1991 7
1011 1992 8 **
1011 1994 7
1011 1995 7
The data set that I want:
1004 1990 13
1004 1991 12
1004 1992 9
1004 1993 9
1004 1994 10
1004 1995 10
1004 1996 10
1004 1997 10 **
1004 1998 10 **
1004 1999 10 **
1004 2000 9
1011 1990 7
1011 1991 7
1011 1992 8
1011 1993 8 **
1011 1994 7
1011 1995 7
Thanks very much.
|