**Date:** Thu, 17 May 2012 20:08:47 -0400
**Reply-To:** Nat Wooding <nathani@VERIZON.NET>
**Sender:** "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
**From:** Nat Wooding <nathani@VERIZON.NET>
**Subject:** Re: datastep matching obs problem
**In-Reply-To:** <CAFRTgcw=mMWQwH074RApQ9O5rDkAtKGxA2iJ6J48UdiE=wsKdg@mail.gmail.com>
**Content-Type:** text/plain; charset="US-ASCII"
JD

It looks like no one has offered a public solution so try this one.

Nat Wooding

data have;
infile datalines missover;
input partno $2. @4 part_w_tag $2. @7 part_opposite $2.;
datalines;
a2 a1
ab aa
b1 b1 b2
b2 b1
c1 c1 c2
c1 c1 c2
c2 c1
;
Data BadParts;
set have ( where = ( part_w_tag gt ' ')) end = eof;
retain fmtname 'Suspect'
type 'C';
length label $2.;
label =Partno;
start=part_opposite;
output;
drop part: ;
output;
IF EOF THEN DO;
HLO='O';
LABEL='';
start = ' ';
OUTPUT;
end;
run;
Proc sort data = badparts nodupkey;
by start;
run;

proc format cntlin=badparts print;
RUN;

Data Want;
set have;
if part_w_tag = '' then part_w_tag = put( partno , $suspect. );
run;

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of JD
Sent: Wednesday, May 16, 2012 9:44 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: datastep matching obs problem

My example was too 'clean'. Here is one that is slightly more realistic
without putting a bunch of real part numbers in:

data have;
infile datalines missover;
input partno $2. @4 part_w_tag $2. @7 part_opposite $2.;
datalines;
a2 a1
ab aa
b1 b1 b2
b2 b1
c1 c1 c2
c1 c1 c2
c2 c1
;
data want;
infile datalines missover;
input partno $2. @4 part_w_tag $2. @7 part_opposite $2.;
datalines;
a2 a1
ab aa
b1 b1 b2
b2 b1 b1
c1 c1 c2
c1 c1 c2
c2 c1 c1
;

The original problem is that I have Part Numbers (partno) that are being
written up for quality problems. Some of these part numbers have a mirror
opposite part (part_opposite). If a part number with a mirror opposite is
written up, then, for reporting purposes I need to count both of those parts
as potential problems. So in this case, partno b1 has a tag. Its opposite
part is b2. Thus, when I run across b2 in the partno column, I need to
associate it with partno b1. That way I'll know that I have to watch b1 and
b2 for potential problems in the future. Does that make sense?

On Wed, May 16, 2012 at 6:41 PM, Nat Wooding <nathani@verizon.net> wrote:

> JD
>
> Your explanation eludes me but it appears that if Parta is greater
> than (meaning that in sort order, it would sort after partc) partc,
> then you want to set partb to the value of partc.
>
> The following code does this, at least for the example data that you
> offered.
>
> Nat Wooding
>
>
> data have;
> infile datalines missover;
> input parta $2. @4 partb $2. @7 partc $2.;
> datalines;
> a1 a2
> b1 b1 b2
> b2 b1
> c1 c1 c2
> c1 c1 c2
> c2 c1
> ;
>
> data want;
> set have ;
> if parta gt partc then partb = partc;
> run;
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> JD
> Sent: Wednesday, May 16, 2012 8:22 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: datastep matching obs problem
>
> I have a dataset and need to fill in data (var partb) such that if a
> value is in partc and that same value is also in parta partb will then
> be filled in with value from parta. I hope this example explains it
> better. Thank you.
>
> data have;
> infile datalines missover;
> input parta $2. @4 partb $2. @7 partc $2.;
> datalines;
> a1 a2
> b1 b1 b2
> b2 b1
> c1 c1 c2
> c1 c1 c2
> c2 c1
> ;
>
> data want;
> infile datalines missover;
> input parta $2. @4 partb $2. @7 partc $2.;
> datalines;
> a1 a2
> b1 b1 b2
> b2 b1 b1
> c1 c1 c2
> c1 c1 c2
> c2 c1 c1
> ;
>