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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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