Date: Tue, 7 Dec 2010 23:59:40 -0500
Reply-To: Arthur Tabachneck <art297@ROGERS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@ROGERS.COM>
Subject: Re: Groupings
Same idea as Yu, but with a different suggested ordering:
proc sort data=have;
by id date vara;
run;
data want;
set have;
by id date vara;
if first.date then flagA=0;
if not(first.vara and last.vara) then do;
flag=1;
if first.vara then flagA+1;
end;
else flag=0;
run;
HTH,
Art
---------
On Tue, 7 Dec 2010 22:40:09 -0600, Yu Zhang <zhangyu05@GMAIL.COM> wrote:
>Randy,
>
>I Assumed that the data is pre-sorted by date Id and VarA. otherwise you
>need to add a proc sort to sort the data.
>
>HTH
>
>Yu
>
>data have;
>input
>Date :date9. ID VarA;
>cards;
>01FEB2010 1 24
>01FEB2010 1 51
>01FEB2010 1 51
>01FEB2010 1 54
>01FEB2010 1 62
>01FEB2010 1 62
>01FEB2010 1 62
>02FEB2010 1 5
>02FEB2010 1 7
>02FEB2010 1 9
>02FEB2010 1 9
>02FEB2010 1 9
>01FEB2010 2 1
>01FEB2010 2 1
>01FEB2010 2 1
>01FEB2010 2 5
>01FEB2010 2 7
>01FEB2010 2 7
>02FEB2010 2 8
>02FEB2010 2 10
>02FEB2010 2 12
>02FEB2010 2 14
>02FEB2010 2 14
>;
>run;
>
>data want;
>set have;
>by Date ID VarA notsorted;
>if first.varA and last.varA then flag=0;
>else flag=1;
>if first.id then temp=0;
>if first.varA and not last.varA then temp+1;
>if flag=0 then flagA=0;
>else flagA=temp;
>drop temp;
>run;
>
>On Tue, Dec 7, 2010 at 9:43 PM, Randy <randistan69@hotmail.com> wrote:
>
>> The rule is that on a day for a ID, if there is more than one VarA then
the
>> flag is 1 else the flag is 0.
>> For FlagA I am grouping the cases where there is more than one case of
>> VarA,
>> on a day for an ID
>>
>> Randy
>>
>> On Tue, 7 Dec 2010 19:18:57 -0800, Jeremy Miles <jeremy.miles@GMAIL.COM>
>> wrote:
>>
>> >I don't see the rule that means that 24 becomes 0, 0 , 51 becomes 1, 1,
62
>> >becomes 1, 2.
>> >
>> >But I might be missing something. Could you explain?
>> >
>> >J
>> >
>> >On 7 December 2010 19:04, Randy <randistan69@hotmail.com> wrote:
>> >
>> >> My Data is as follows:
>> >>
>> >>
>> >> Date ID VarA
>> >> 01FEB2010 1 24
>> >> 01FEB2010 1 51
>> >> 01FEB2010 1 51
>> >> 01FEB2010 1 62
>> >> 01FEB2010 1 62
>> >> 01FEB2010 1 62
>> >> 02FEB2010 1 5
>> >> 02FEB2010 1 7
>> >> 02FEB2010 1 9
>> >> 02FEB2010 1 9
>> >> 02FEB2010 1 9
>> >> 01FEB2010 2 1
>> >> 01FEB2010 2 1
>> >> 01FEB2010 2 1
>> >> 01FEB2010 2 5
>> >> 01FEB2010 2 7
>> >> 01FEB2010 2 7
>> >> 02FEB2010 2 8
>> >> 02FEB2010 2 10
>> >> 02FEB2010 2 12
>> >> 02FEB2010 2 14
>> >> 02FEB2010 2 14
>> >>
>> >> I want to group VarA by adding two flags:
>> >>
>> >> Date ID Var Flag FlagA
>> >> 01FEB2010 1 24 0 0
>> >> 01FEB2010 1 51 1 1
>> >> 01FEB2010 1 51 1 1
>> >> 01FEB2010 1 62 1 2
>> >> 01FEB2010 1 62 1 2
>> >> 01FEB2010 1 62 1 2
>> >> 02FEB2010 1 5 0 0
>> >> 02FEB2010 1 7 0 0
>> >> 02FEB2010 1 9 1 1
>> >> 02FEB2010 1 9 1 1
>> >> 02FEB2010 1 9 1 1
>> >> 01FEB2010 2 1 1 1
>> >> 01FEB2010 2 1 1 1
>> >> 01FEB2010 2 1 1 1
>> >> 01FEB2010 2 5 0 0
>> >> 01FEB2010 2 7 1 2
>> >> 01FEB2010 2 7 1 2
>> >> 02FEB2010 2 8 0 0
>> >> 02FEB2010 2 10 0 0
>> >> 02FEB2010 2 12 0 0
>> >> 02FEB2010 2 14 1 1
>> >> 02FEB2010 2 14 1 1
>> >>
>> >> Please help
>> >>
>> >> Randy
>> >>
>> >
>> >
>> >
>> >--
>> >Jeremy Miles
>> >Psychology Research Methods Wiki: www.researchmethodsinpsychology.com
>>
|