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 (March 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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. > > [snip] > > 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 > > L=2 > > 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 > > B=1 > > 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 > > B=0 > > for reasons which I cannot explain.

I can state empirical observation but not reconcile with current understanding.

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().

data _null_; B1 = ( compbl ('') =: ' ' ); B2 = ( compress('') =: ' ' ); B3 = ( compbl ('') =: '' ); B4 = ( compress('') =: '' ); B5 = ( '' =: 'Foo' ); B6 = ( '' =: ' Foo' ); B7 = ( '' =: '' ); B8 = ( '' =: ' ' );

x1 = '.'||compress('')||'.'; x2 = '.'||trim('')||'.'; x3 = '.'||compbl('')||'.';

x4 = compress('');

put (B:)(/=); put (X:)(/=);

Lx1 = vlengthx('x1'); Lx2 = vlengthx('x2'); Lx3 = vlengthx('x3'); Lx4 = vlengthx('x4'); put (lx:)(/=);

bx4 = peek(addr(x4)); put bx4= hex2.; run;

----- v9.1 log B1=1 B2=0 B3=1 B4=0 B5=0 B6=1 B7=1 B8=1

x1=.. <- is compress('') length 0 ? x2=. . x3=. . x4=

Lx1=3 <- is compress('') length is 1 ? Lx2=3 Lx3=3 Lx4=1 bx4=20

----- v8.2 log B1=1 B2=0 B3=1 B4=0 B5=0 B6=1 B7=1 B8=1

x1=.. x2=. . x3=. . x4=

Lx1=3 Lx2=3 Lx3=202 Lx4=1 bx4=20

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 blank "

and "Comparisons

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 http://www.devenezia.com


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