| Date: | Mon, 10 Jul 2000 19:33:52 GMT |
| Reply-To: | sashole@mediaone.net |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Paul Dorfman <paul_dorfman@HOTMAIL.COM> |
| Subject: | Re: Help needed! |
|
| Content-Type: | text/plain; format=flowed |
|---|
James,
Using Ian's own old trick, it can be done even more economically:
data c (drop=f);
do until (last.studid);
set a; by studid;
if f then continue;
output;
if grade = 70 then f = 1;
end;
run;
It will run just a bit more efficiently, because 1) the flag is reset at
the end of each by-group automatically (which is just a tad faster than
resetting it explicitly) 2) the bottom and top of the step are reached the
number of times equal to the number of by-groups instead of number of
observations, hence reducing the amount of housekeeping. Plus, there is no
need to retain anything :-).
Kind regards,
===================
Paul M. Dorfman
Jacksonville, Fl
===================
>From: James Yang <jamesy99@HOTMAIL.COM>
>Reply-To: James Yang <jamesy99@HOTMAIL.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Help needed!
>Date: Mon, 10 Jul 2000 14:14:40 EDT
>
>Thank you all very much: Ian, Ya, Nancy, Nat, Rob, Puddin', Kelly. I
>learned
>a lot from you experts. Thanks again!
>
>James
>
>
>>From: Ian Whitlock <WHITLOI1@WESTAT.com>
>>To: 'Ya Huang' <ya.huang@AGOURON.COM>
>>CC: 'James Yang' <jamesy99@HOTMAIL.COM>
>>Subject: RE: Help needed!
>>Date: Mon, 10 Jul 2000 13:43:10 -0400
>>
>>Ya,
>>
>>You should do it with one flag, then the code is easier to understand.
>>
>>data xx;
>> set xx;
>> retain outflg 1;
>> by studid;
>> if first.studid then outflg = 1 ;
>> if outflg then output ;
>> if grade =70 then outflg = 0 ;
>>run ;
>>
>>Ian Whitlock <whitloi1@westat.com>
>>
>>-----Original Message-----
>>From: Ya Huang [mailto:ya.huang@AGOURON.COM]
>>Sent: Monday, July 10, 2000 1:17 PM
>>To: SAS-L@LISTSERV.UGA.EDU
>>Subject: Re: Help needed!
>>
>>
>>James, try the following:
>>
>>data xx;
>>input studID $ GRADE;
>>cards;
>>01 90
>>01 96
>>01 70
>>01 50
>>01 70
>>02 80
>>02 70
>>02 90
>>02 76
>>;
>>
>>data xx;
>> set xx;
>>retain flag1 flag2;
>>by studid;
>>if first.studid then do; flag1=0; flag2=0; end;
>>if grade =70 then do; flag1=1; flag2+1; end;
>>if flag2 gt 0 then flag2+1;
>>if flag1 and flag2 > 2 then delete;
>>
>>options nocenter;
>>
>>proc print;
>>run;
>>
>>---------------------------------------
>>OBS STUDID GRADE FLAG1 FLAG2
>>
>> 1 01 90 0 0
>> 2 01 96 0 0
>> 3 01 70 1 2
>> 4 02 80 0 0
>> 5 02 70 1 2
>>
>>
>>
>>James Yang wrote:
>> >
>> > I have following dataset: J1 with 2 vars:
>> >
>> > StudID GRADE
>> > 01 90
>> > 01 96
>> > 01 70
>> > 01 50
>> > 01 70
>> > 02 80
>> > 02 70
>> > 02 90
>> > 02 76
>> >
>> > What I want to do now is: for a given student, all records after the
>>first
>> > time grade=70 are deleted. That is, for this specific example,
>>following
>> > will be my expected output dataset:
>> >
>> > StudID GRADE
>> > 01 90
>> > 01 96
>> > 01 70
>> > 02 80
>> > 02 70
>> >
>> > How can make this efficiently? Any advice is appreciated in advance.
>> >
>> > James
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
|