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 (September 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 22 Sep 2000 13:57:35 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      SAS Trap (Character Comparisons)
Content-Type: text/plain; charset=US-ASCII

Here's something which gave me problems this week.

It involves character comparisons on operands of different lengths, with trailing blanks.

Start with a simple case (no trailing blanks):

'ab' = 'abc'

evaluates to false because SAS pads the shorter string to the length of the longer. This can be modified by inserting a colon. To quote the V. 8 documentation:

"When making character comparisons, you can use a colon (:) after any of the comparison operators to compare only the first character(s) of the value. The SAS System truncates the longer value to the length of the shorter value during the comparison. For example, if name=:'P' compares the value of the first character of NAME to the letter P. "

So

'ab' =: 'abc'

evaluates to true.

But I was working with variables. Here's a simplified example:

data ... input prefix $; cards; ab ;

Then:

prefix =: 'abc'

evaluates to false because when SAS "truncates the longer value to the length of the shorter value" it does not first trim trailing blanks. So in this case, PREFIX has the default length of 8 and a value of 'ab ' (6 trailing blanks), which gets shortened to 'ab ' (one trailing blank) then compared to 'abc'.

The solution is to code

trim(prefix) =: 'abc'

which evaluates to true.


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