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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 650 views
  • 0 likes
  • 2 in conversation