Date: Sun, 2 Mar 2008 23:51:44 -0600
Reply-To: Yu Zhang <zhangyu05@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Yu Zhang <zhangyu05@GMAIL.COM>
Subject: Re: compare two string
Content-Type: text/plain; charset=ISO-8859-1
First, from SAS doc,
In the COMPARE function, if string-1 and string-2 do not differ, COMPARE
returns a value of zero. If the arguments differ
the sign of the result is negative if string-1 precedes string-2 in a
sort sequence, and positive if string-1 follows string-2 in a sort
in your exmple, you are using modifier 'IL',which tell SAS to ignore the
case and remove the leading blanks. since the string1 has shoter length than
string2. so before comparison, SAS add trailing blanks to make two string
same length. blank is smaller than any non-missing letters. string1 will be
smaller than string2. the negative sign will be in the result.
On Sun, Mar 2, 2008 at 11:24 PM, Irene <email@example.com> wrote:
> String1="abc" String2="ABCDEFG"
> compare(string1, string2, 'IL')=-4
> why? I can not understand why it is equal negative 4. I know that the
> two string are different from the fourth character but why negative?
> Thanks for your help!