Date: Thu, 10 Feb 2005 13:39:00 -0500
Reply-To: Nathaniel_Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: Antwort: Re: Comparison of text strings
Content-type: text/plain; charset=US-ASCII
Armin told me off list that he/she wants to compare from the beginning so
here is a solution.
Nat Wooding
data a;
LENGTH string1 string2 $ 10;
input string1 $ string2 $;
cards;
ABCdef ABCXYZ
ABCdef xyABCdef
ABCDEFGHIJ ABCDEFGHIJ
proc print;run;
data b;
set;
length shared $ 10;
shared=' ';
drop i c1 c2;
do i = 1 to LENGTH(STRING1);
c1=substr(string1,i,1);
c2=substr(string2,i,1);
if (c1=c2) and c1 gt '' then shared=compress(shared||c1);
else leave;
end;
proc print;
run;
Armin_Bauerbach@dade
behring.com To: Nathaniel_Wooding@dom.com
cc:
02/10/05 10:22 AM Subject: Antwort: Re: Comparison of text strings
Nathaniel
I would get the part of string agreeing from the begining:
"ABCdef" vs. "ABCXYZ" is "ABC"
"ABCdef" vs. "xyABCdef" is ""
or in case of three string:
"ABCdef" vs. "ABCxyz" vs "ABgxyz" is "AB"
Armin Bauerbach
|---------+---------------------------->
| | Nathaniel_Wooding|
| | @dom.com |
| | |
| | 10.02.2005 16:14 |
| | |
|---------+---------------------------->
>--------------------------------------------------------------------------------------------------------------|
|
|
| An: Armin Bauerbach <armin_bauerbach@DADEBEHRING.COM>
|
| Kopie:
|
| Thema: Re: Comparison of text strings
|
>--------------------------------------------------------------------------------------------------------------|
Armin
Will you always want to start at the begining of each string and compare
them character by character or could you have cases like
AbCd abd giving bd
or
ABCe vs aaaBC giving BC
Nat Wooding