Help using Base SAS procedures

By Group Progressing

Reply
N/A
Posts: 0

By Group Progressing

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...)
Respected Advisor
Posts: 3,799

Re: By Group Progressing

Posted in reply to deleted_user
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]
N/A
Posts: 0

Re: By Group Progressing

Posted in reply to data_null__
looks perfect. thanks very much
Ask a Question
Discussion stats
  • 2 replies
  • 92 views
  • 0 likes
  • 2 in conversation