Hi guys,
I am trying to create a dummy where the year is equal to the audit year. There are multiple observations for a particular firm.
Firm ID Year Audit_year Dummy (what I want)
11 1990 . 0
11 1991 . 0
11 1992 1993 0
11 1993 . 1
11 1993 . 1
11 1993 . 1
11 1994 1995 0
11 1995 . 1
11 1996 . 0
12 2001 . 0
12 2002 2003 0
12 2003 . 1
12 2004 . 0
12 2005 . 0
12 2006 . 0
12 2007 . 0
12 2008 . 0
12 2009 . 0
In the latter table, audit years are one year ahead of YEAR. Please help with respect to the codes
Regards,
Amanjot
data have;
input FirmID Year Audit_year;
datalines;
11 1990 .
11 1991 .
11 1992 1993
11 1993 .
11 1993 .
11 1993 .
11 1994 1995
11 1995 .
11 1996 .
12 2001 .
12 2002 2003
12 2003 .
12 2004 .
12 2005 .
12 2006 .
12 2007 .
12 2008 .
12 2009 .
;
data want(drop=_:);
merge have
have (firstobs=2 keep=FirmID Year rename=(FirmID=_FirmID Year=_Year));
dummy = FirmID = _FirmID & Audit_year = _Year;
run;
Result:
FirmID Year Audit_year dummy 11 1990 . 0 11 1991 . 0 11 1992 1993 1 11 1993 . 0 11 1993 . 0 11 1993 . 0 11 1994 1995 1 11 1995 . 0 11 1996 . 0 12 2001 . 0 12 2002 2003 1 12 2003 . 0 12 2004 . 0 12 2005 . 0 12 2006 . 0 12 2007 . 0 12 2008 . 0 12 2009 . 0
Hi @amanjot_42
Here is an attempt to do this:
data want (drop = _Audit_year);
set have;
if Audit_year ne . then _Audit_year=0;
_Audit_year + Audit_year;
if _Audit_year = Year then Dummy = 1;
else Dummy = 0;
run;
Output
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.