Date: Wed, 4 May 2005 10:54:50 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject: Re: if flag is y delete all associated
It's possible to avoid the renaming business by switching the order of the
MERGE. The code would be something like:
data selected;
merge sorted (keep=id flag where=(flag eq 1) in=_flagged)
sorted;
by id;
if not _flagged;
run;
This is unusual in that it is a many-to-many MERGE. Moreover, there are
colliding values for FLAG. Usually these are things to avoid, especially in
combination. Here they are OK.
If the given data set is grouped by ID, but not sorted in ascending or
descending sequence, a Double DoW approach can eliminate the need to sort.
The code would be something like:
data selected(drop=flags);
flags = 0;
do until (last.id);
set groupedButNotSorted;
by id notsorted;
flags ++ (flag=1);
end;
do until (last.id);
set groupedButNotSorted;
by id notsorted;
if not flags then output;
end;
run;
On Wed, 4 May 2005 07:19:53 -0400, Dennis Diskin <ddiskin@GMAIL.COM> wrote:
>David,
>
>Ya has already given you a concise SQL solution. If you prefer
>datastep, you already have an outline of a good approach except that
>it is unnecessary to create a separate file. Instead use dataset
>subsetting where option:
>
>1. sort file on ID then:
>
>data selected(drop=_flag);
>merge sorted sorted(where=(_flag eq 1) in=_flagged keep=id flag
>rename=flag=_flag);
>by id;
>if not _flagged;
>run;
>/* the renaming is to avoid overwriting the flag variable in the kept
>records. */
>
>
>HTH,
>Dennis Diskin
>
>On 5/4/05, David Fickbohm <davefickbohm@yahoo.com> wrote:
>> People,
>> I have a file with an ID field and a flag field. There can be multiple
records with the same value in the ID Field. Each record will also have a
flag field. If one of the flag fields has a value of 1 then I need to
delete all records where the ID field has the same value as the record
where the flag fields value is 1.
>>
>> All of the records with the same value in the ID field will be grouped
together.
>>
>> My approach is to search for flag fields with a 1, then write the ID
fields value to a file containing only ID fields and flag fields. each
flag field should contain a 1.
>>
>> Then I would use that file to delete all records where the value in the
ID field matched the value in the ID field in the original file.
>>
>> Your thoughts, ideas, etc. will be greatly appreciated.
>> Thanks
>> Dave
>>
>> Dave Fickbohm
>> Use Technology to the Fullest
>> 1250 45th st suite 200
>> Emeryville, CA, 94608
>> 510 594 4151 voice
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>>
|