BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

 

data want;
set have;
by id;
flag=lag(events);
if first.id then flag=.;
if flag=1 then delete;
drop flag;
run;
Thanks,
Jag
novinosrin
Tourmaline | Level 20

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;
Ksharp
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1005 views
  • 2 likes
  • 4 in conversation