Date: Wed, 31 Mar 2004 14:35:32 -0500
Reply-To: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject: Re: DO Loop Behavior with Increment of Zero
Howard Schreier wrote:
> On Sat, 27 Mar 2004 22:31:05 -0500, Howard Schreier
> <Howard_Schreier@ITA.DOC.GOV> wrote:
>> I understand that SAS caanot store a null/zero-length character
>> value in a variable. But that is a separate issue from the
>> evaluation of character expressions. In
>> null = '' ;
>> the right hand side yields a null string. The padding with blanks
>> happens when the value is stored.
> WRONG!! The right hand side yields a string consisting of a single
> space character.
> This is the experiment which convinced me:
> L = length( '' || '*' ); put L=;
> The result is
> I believe that this is a compile-time phenomenon. Just as SAS cannot
> store a null string (meaning a string with zero length) in a
> variable, SAS cannot store such a string in compiled code.
> My earlier point still holds. I just need a different example, one
> which will compute a null string at execution time, such as
> null = compress( '*' , '*' );
> Now here's something I can't figure out. Let's compare a null string
> with a string of blanks
> B = ( compress( ' ' ) = ' ' ); put B=;
> The shorter value is padded to the length of the longer one, so we get
> as expected. Now introduce the colon modifier so that the longer
> string is truncated to the length of the shorter one
> B = ( compress( ' ' ) =: ' ' ); put B=;
> I still expect the two to be found equal, but the result is
> for reasons which I cannot explain.
I can state empirical observation but not reconcile with current
compress('') is special case function that can return a zero length string!
and as such is restricted to not being allowed as a prefix match.
Additionally inconsistentcy, I presume compress('') is 'length 1' when
contributing to a variables length (as part of an expression that is the
basis of defining required length to store a value in the variable).
What does the rulebook have to say ?
The version 9.1 online help states zero-length-string...
If you call the COMPRESS function with...
only the first argument, source
The result is...
The argument with all blanks removed.
If the argument is completely blank, then the result is a string with a
length of zero. If you assign the result to a character variable with a
fixed length, then the value of that variable will be padded with blanks to
fill its defined length.
version 8.2 online help is not helpful regarding compress().
B1 = ( compbl ('') =: ' ' );
B2 = ( compress('') =: ' ' );
B3 = ( compbl ('') =: '' );
B4 = ( compress('') =: '' );
B5 = ( '' =: 'Foo' );
B6 = ( '' =: ' Foo' );
B7 = ( '' =: '' );
B8 = ( '' =: ' ' );
x1 = '.'||compress('')||'.';
x2 = '.'||trim('')||'.';
x3 = '.'||compbl('')||'.';
x4 = compress('');
Lx1 = vlengthx('x1');
Lx2 = vlengthx('x2');
Lx3 = vlengthx('x3');
Lx4 = vlengthx('x4');
bx4 = peek(addr(x4));
put bx4= hex2.;
----- v9.1 log
x1=.. <- is compress('') length 0 ?
Lx1=3 <- is compress('') length is 1 ?
----- v8.2 log
Regarding Trim() and TrimN() [new in v9]
TRIM copies a character argument, removes all trailing blanks, and returns
the trimmed argument as a result. If the argument is blank, TRIM returns one
The TRIM and TRIMN functions are similar. TRIM returns one blank for a blank
string. TRIMN returns a null string (zero blanks) for a blank string.
Richard A. DeVenezia