|
On May 20, 1:29 pm, Nathaniel.Wood...@DOM.COM (Nat Wooding) wrote:
> Here's a data step solution.
>
> data a;
> input member_id month value ;
> cards;
> 1 1 0
> 1 3 1
> 1 3 4
> 1 3 8
> 1 12 10
> 2 1 0
> 2 1 2
> 2 9 22
> 2 9 5
> 2 9 17
> ;
> run;
>
> proc sort data=a;
> by member_id month;
> run;
>
> data a ( keep = member_id month value bad_event )
> b (keep = member_id month bad_event_in_member_id_and_month) ;
> set a;
> by member_id month;
> retain bad_event 0;
> if first.month then bad_event = 0;
> bad_event = max( ( value > 7 ) , bad_event );
> * the code fragment (Value > 7 ) evaluates to either a 0 or 1
> depending on whether
> * value is greater than 7;
> output a;
> if last.month then do;
> if bad_event then bad_event_in_member_id_and_month = 'Yes';
> else bad_event_in_member_id_and_month = 'No';
> output b;
> end;
> run;
>
> Data final;
> merge a b;
> by member_id month;
> run;
>
> proc print;
> run;
>
> Nat Wooding
> Environmental Specialist III
> Dominion, Environmental Biology
> 4111 Castlewood Rd
> Richmond, VA 23234
> Phone:804-271-5313, Fax: 804-271-2977
>
> sas 9 bi user
> <sas...@GMAIL.COM
> > To
> Sent by: "SAS(r) SA...@LISTSERV.UGA.EDU
> Discussion" cc
> <SA...@LISTSERV.U
> GA.EDU> Subject
> Easy question - Data step
> processing
> 05/19/2008 11:45
> PM
>
> Please respond to
> sas 9 bi user
> <sas...@GMAIL.COM
> >
>
> /*
> All say I have the below. Suppose if in a given month, the a member's
> Value
> (see below) is >7. In that case I flag it as a "bad event". Bad event =
> value >7.
>
> My question is, if there is a "bad event" in a given month, how to I flag
> the whole month as having a "bad event"? See below, it should make more
> sense.
> Thanks in advance for your wisdom...
>
> */
>
> data a;
> input member_id month value ;
> cards;
> 1 1 0
> 1 3 1
> 1 3 4
> 1 3 8
> 1 12 10
> 2 1 0
> 2 1 2
> 2 9 5
> 2 9 17
> ;
> run;
>
> proc sort data=a;
> by id month;
> run;
>
> data b;
> set a;
> if value >7 then bad_event = 1; else bad_event =0;
> run;
>
> proc print;
> run;
>
> /* I want the final to look like this, basically, if a member has an event
> (value >7) then their flag for the whole month is YES (as indicated by the
> last column (bad_event_in_member-id_and_month?).
>
> member_id month value bad_event bad_event_in_member-id_and_month?
> 1 1 0 0 NO
> 1 3 1 0 YES
> 1 3 4 0 YES
> 1 3 8 1 YES
> 1 12 10 1 NO
> 2 1 0 0 NO
> 2 1 2 0 NO
> 2 9 5 0 YES
> 2 9 17 1 YES
>
> */
and yet another data step solution
This assumes that data are in data set work.A in member_ID order.
It passes through the data (apparently) twice, but in a single SET
statement using by member_ID it should perform OK.
At least it is brief ---> :
data b;
set a( in=testing_pass) a(application_pass);
by member_ID ;
if first.member_ID then bad_event = 0 ;
retain bad_event ;
if testing_pass then do;
if value >7 then bad_event = 1;
end;
if application_pass ;
run;
PeterC
|