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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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