Date: Mon, 23 Feb 2009 06:45:16 +0000
Reply-To: Paul Dorfman <sashole@BELLSOUTH.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <sashole@BELLSOUTH.NET>
Organization: PDC
Subject: Re: string comparison within same data set
In-Reply-To: <200902230219.n1MBuDvp008716@malibu.cc.uga.edu>
Content-Type: text/plain; charset="utf-8"
Zibia,
For a change, try
data a ; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
  input id code: $7. ;                         Â
  cards ;                                Â
1 Â 1234567 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
1 Â 1234568 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
1 Â 1294568 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
2 Â 0123456 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
3 Â 4567812 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
3 Â 4567812 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
3 Â 9567812 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
4 Â 1212121 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
4 Â 1212189 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
run ; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
                                     Â
data b (keep = id) ; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
  do until (last.id) ;                         Â
    set a ;                              Â
    by id ;                              Â
    if first.id then fc = code ;                    Â
    do x = 1 to length (code) ;                    Â
     if char (fc, x) ne char (code, x) then substr (fc, x, 1) = "*" ;
    end ;                               Â
  end ;                                 Â
  if countC (fc, "*") => 2 ;                      Â
run ; Â Â Â
Kind regards
------------
Paul Dorfman
Jax, FL
------------ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
 -------------- Original message from Zibia Zhang <zzhang@HSPH.HARVARD.EDU>: --------------
> Dear all,
>
> I have a data set which has two variables, id and code, id is number, code
> is a fixed length of string. Like:
> ID code
> 1 3456789
> 1 3466789
> 2 4321456
> 2 4321456
>
> I would like pick up all the ids which has different codes. But only if two
> or more positions are different between the codes is defined as different.
> for example, ID 1 will not be picked up, because there is only one position
> is different. Anybody has any idea how to do this?
>
> Thanks.
|