Hello everyone, I have the following data set,
Ticker Year Net income Net income is negative in the past two years? (yes=1, no=0)
A 2000 2
A 2001 -1
A 2002 1 0
A 2003 -1 0
A 2004 -3 1
A 2005 -2 1
B 2001 3
B 2002 4
B 2003 -1 0
B 2004 -2 1
My question is how to construct "Net income is negative in the past two years", the last column?
Use the LAG() and LAG2() function.
data have;
input Ticker $ Year Netincome ;
cards;
A 2000 2
A 2001 -1
A 2002 1 0
A 2003 -1 0
A 2004 -3 1
A 2005 -2 1
B 2001 3
B 2002 4
B 2003 -1 0
B 2004 -2
;
proc sql;
create table want as
select *,case when
(select sum(netincome) from have
where ticker=a.ticker and year between a.year-1 and a.year)<0 then 1
else 0 end as flag
from have as a;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.