Date: Tue, 14 Nov 2006 22:02:37 -0500
Reply-To: Jerry L Diebal <jdiebal@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jerry L Diebal <jdiebal@GMAIL.COM>
Subject: Re: Subsetting by specific patterns
In-Reply-To: <200611142339.kAEKsAdl027984@mailgw.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
I tried the solutions from both Arthur and Ya Huang. Both do exactly what I
needed. I really appreciate the quick responses. Thank you.
On 11/14/06, Arthur Tabachneck <art297@netscape.net> wrote:
>
> Jerry,
>
> Your file of acceptable values doesn't match your set of requirements. If
> it did, Ya's code appears to work.
>
> Alternatively, if you don't really need a requirement file, you could just
> solve your problem in a simple data step. For example:
>
> data want;
> set PARTLIST;
> by partno;
> if first.partno then matchno=0;
> if matchno eq 0 then do;
> if wc eq 'WAR02' then matchno+1;
> end;
> else if matchno eq 1 then do;
> if wc eq 'MMJ03' then matchno+1;
> else matchno=0;
> end;
> else if matchno eq 2 then do;
> if wc in ('MMS03','MMS24','MMS27','MMS04','MMS05') then matchno+1;
> else matchno=0;
> end;
> else if matchno eq 3 then do;
> if wc in ('MMS07','MMS08') then matchno+1;
> else matchno=0;
> end;
> if matchno=4 then match='Y';
> else match='N';
> if last.partno then output;
> run;
>
> HTH,
> Art
> -----------
> On Tue, 14 Nov 2006 17:44:45 -0500, Jerry L Diebal <jdiebal@GMAIL.COM>
> wrote:
>
> >I have two datasets: wc_seq and partlist. WC_SEQ will contain all
> possible
> >'good' WC combinations. I need to find all
> >parts that have one of the sequence combinations below. The part has to
> have
> >one of the 4-sequence combinations in
> >the list below in order to be considered a match. The WC's have to be
> >contiguous and in the sequence like below. It doesn't
> >matter if the part has additional wc's before or after the sequence
> >combination as long as the 4 wc's are contiguous.
> >
> >Thanks in advance.
> >
> >
> >/*possible contiguous sequence combinations:*/
> >/* first:
> >WAR02
> >*/
> >/* second: MMJ03
> > */
> >/* third: MMS03 or MMS24 or MMS27 or MMS04 or MMS05 */
> >/* fourth: MMS07 or MMS08
> > */
> >
> >
> >/*example sequence combinations (the sequence variable indicates what
> >sequence each wc belongs to.*/
> >data wc_seq;
> > input wc$ sequence;
> >cards;
> >
> >WAR02 1
> >MMJ03 1
> >MMS03 1
> >MMS07 1
> >
> >WAR02 2
> >MMJ03 2
> >MMS24 2
> >MMS07 2
> >
> >WAR02 3
> >MMJ03 3
> >MMS27 3
> >MMS07 3
> >;
> >
> >data PARTLIST;
> > input PARTNO$ OPNO WC$;
> >cards;
> >
> >PART1 05 WAR99
> >PART1 10 WAR02
> >PART1 20 MMJ03
> >PART1 30 MMS03
> >PART1 40 MMS07
> >PART2 10 WAR02
> >PART2 20 MMJ03
> >PART2 30 MMS24
> >PART2 40 MMS07
> >PART3 10 WAR02
> >PART3 20 MMJ03
> >PART3 30 MMS27
> >PART3 40 MMS07
> >PART4 10 WAR99
> >PART4 20 WAR02
> >PART4 30 MMJ03
> >PART4 40 MMJ44
> >PART4 50 MMS27
> >PART4 60 MMS07
> >PART5 10 WAR99
> >PART5 20 WAR02
> >PART5 30 MMJ03
> >PART5 40 MMS27
> >PART5 40 MMS11
> >;
> >
> >
> >/*This is what the output should look like:*/
> >DATA match;
> > input partno$ match$;
> > CARDS;
> > PART1 Y
> > PART2 Y
> > PART3 Y
> > PART4 N
> > PART5 N
> >;
> >RUN;
> >
> >/*
> >part1 - matches sequence 1
> >part2 - matches sequence 2
> >part3 - matches sequence 3
> >part4 - no match since mmj44 in op 40 is not in one of the sequences
> listed
> >in wc_seq dataset.
> >part5 - no match since mms11 in op 40 is not in one of the sequences
> listed
> >in wc_seq dataset.
> >*/
>
|