My data is a panel of industry-years. Some industry-years have a value of 1 for an indicator variable "PERSISTENT." (Otherwise, PERSISTENT is missing.) Some industries do not have any years for which PERSISTENT is 1, and the years in which PERSISTENT takes on a value of 1 may vary by industry.
How can I recode PERSISTENT such that it takes on values of 0 before the industry-year observation that currently has a 1 AND takes on values of 1 for all industry-years afterward?
data want;
by industry;
retain flag;
if first.industry then flag=0;
if persistent=1 then flag=1;
run;
Show what your data looks like, is it long or wide?
Industry | Year | PERSISTENT |
11 | 1992 | |
11 | 1993 | |
11 | 1994 | |
11 | 1995 | 1 |
11 | 1996 | |
11 | 1997 | |
11 | 1998 | |
11 | 1999 | |
11 | 2000 | |
11 | 2001 | |
11 | 2002 | |
11 | 2003 | |
11 | 2004 | |
11 | 2005 | |
11 | 2006 |
That's an example of what the data looks like. I guess that's long?
data want;
by industry;
retain flag;
if first.industry then flag=0;
if persistent=1 then flag=1;
run;
Thank you so much. I was vastly overthinking it (thought I needed to do an array).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.