BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,

I have data in the following fashion (below) and want to remove all observations that happen after action=1 within an ID group (So the bold rows below would be removed in this example).

ID Date Action_Occurs
1234 07/01/2008 0
1234 01/06/2008 0
1234 11/07/2008 0
1234 16/07/2008 1
1234 08/08/2008 0
1234 02/10/2008 0

4567 27/02/2008 0
4567 22/06/2008 0
4567 20/07/2008 0
4567 12/09/2008 1
7891 14/02/2008 0
7891 08/04/2008 0
7891 20/04/2008 0
7891 04/07/2008 1
7891 14/07/2008 0
7891 27/09/2008 0
7891 16/10/2008 0




I have tried retain statements, if statements, first., last. etc... but can't quite crack it. This seems a quite simple task so am quite frustrated that I can't seem to figure it out in SAS. ANY help on this is much appreciated!

(apologies for the layout of the example data - couldn't see a way of uploading images etc...)
2 REPLIES 2
data_null__
Jade | Level 19
See if this looks right to you

[pre]
data test;
input id:$4. date:ddmmyy. action;
format date date.;
cards;
1234 07/01/2008 0
1234 01/06/2008 0
1234 11/07/2008 0
1234 16/07/2008 1
1234 08/08/2008 0
1234 02/10/2008 0
4567 27/02/2008 0
4567 22/06/2008 0
4567 20/07/2008 0
4567 12/09/2008 1
7891 14/02/2008 0
7891 08/04/2008 0
7891 20/04/2008 0
7891 04/07/2008 1
7891 14/07/2008 0
7891 27/09/2008 0
7891 16/10/2008 0
;;;;
run;
data actioned;
do until(last.id);
set test;
by id;
if not actioned then output;
actioned = actioned max action;
end;
drop actioned;
run;
proc print;
run;

[pre]
deleted_user
Not applicable
looks perfect. thanks very much

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 628 views
  • 0 likes
  • 2 in conversation