Hi,
I want to isolate the first pre-and post observations.
For example,
data example;
input id year event;
datalines;
a 1990 0
a 1991 0
a 1992 0
a 1993 1
a 1994 0
a 1995 0
a 1996 1
a 1997 0
b 1993 0
b 1994 0
b 1995 1
b 1996 0
b 1997 1
b 1998 0
b 1999 0
;
run;
I want to get this dataset. like..
data hope;
input id year event;
datalines;
a 1990 0
a 1991 0
a 1992 0
a 1993 1
a 1994 0
a 1995 0
b 1993 0
b 1994 0
b 1995 1
b 1996 0
;
run;
please help!
Something like this?
data want(drop=flag);
set example;
by id;
if first.id then flag=0;
if event=1 then flag+1;
retain flag;
if flag<2;
run;
I don't follow the logic here. Please be more specific.
Something like this?
data want(drop=flag);
set example;
by id;
if first.id then flag=0;
if event=1 then flag+1;
retain flag;
if flag<2;
run;
No problem 🙂
data example;
input id $ year event;
datalines;
a 1990 0
a 1991 0
a 1992 0
a 1993 1
a 1994 0
a 1995 0
a 1996 1
a 1997 0
b 1993 0
b 1994 0
b 1995 1
b 1996 0
b 1997 1
b 1998 0
b 1999 0
;
run;
data want;
call missing(_e,__e);
do until(last.id);
set example;
by id year;
if event and not _e then _e=1;
else if event and _e then __e=1;
if not __e then output;
end;
drop _:;
run;
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 save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.