LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2005, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 14 Feb 2005 12:37:20 -0500
Reply-To:   Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Subject:   Re: Comparison of text strings

I tried it out with SAS 9.1 and there is a special thing with the compare-function. If the first argument preceeds the second one in sort sequence, the result is negative. So if you want the position of the first-not-equal char, use something like:

8 data a; 9 a="1234567hjgsaajsdhj"; 10 b="12345kdljnklfdlk"; 11 x=abs(compare(a,b)); 12 res=substrn(a,x); 13 put _all_; 14 run;

a=1234567hjgsaajsdhj b=12345kdljnklfdlk x=6 res=67hjgsaajsdhj _ERROR_=0 _N_=1

note the ABS function to ignore the negative sign.

On Mon, 14 Feb 2005 08:58:51 -0800, Armin Bauerbach <armin_bauerbach@DADEBEHRING.COM> wrote:

>Here is a nice answer from a SAS employee I got off line. Since I >havn't installed V9 yet I am not able to check it out. > >Armin Bauerbach > > >In SAS 9, you can use the COMPARE function to find the leftmost >position at which two strings differ. Then take the substring up >to but not including that position using the SUBSTRN function. > >-- > >Warren S. Sarle SAS Institute Inc. The opinions expressed here >saswss@unx.sas.com SAS Campus Drive are mine and not >necessarily >(919) 677-8000 Cary, NC 27513, USA those of SAS Institute.


Back to: Top of message | Previous page | Main SAS-L page