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).
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.