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;
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!
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.