Dear Experts,
I want to delete the rows using a condition given below. Kindly go through my sample dataset for better details.
data have;
input Id Events value;
cards;
101 0 12
101 0 15
101 1 14
101 0 18
108 0 45
108 1 25
108 0 23
;In the given set. I want to delete the row which occurs after the event meets 1.
Rows need to delete :
101 0 18
108 0 23
Kindly suggest some code to solve the task
Thank you!
data have;
input Id Events value;
cards;
101 0 12
101 0 15
101 1 14
101 0 18
108 0 45
108 1 25
108 0 23
;
data want;
do until(last.id);
set have;
by id;
if not n then output;
if EVENTS then n=1;
end;
drop n;
run;
Please try
data want;
set have;
by id;
flag=lag(events);
if first.id then flag=.;
if flag=1 then delete;
drop flag;
run;
data have;
input Id Events value;
cards;
101 0 12
101 0 15
101 1 14
101 0 18
108 0 45
108 1 25
108 0 23
;
data want;
do until(last.id);
set have;
by id;
if not n then output;
if EVENTS then n=1;
end;
drop n;
run;
Just for fun.
data have;
input Id Events value;
cards;
101 0 12
101 0 15
101 1 14
101 0 18
108 0 45
108 1 25
108 0 23
;
data want;
set have;
by id;
retain flag;
lag=lag(events);
if first.id then call missing(lag,flag);
if lag then flag=1;
if flag then delete;
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.