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 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 16 Mar 2003 18:59:06 -0800
Reply-To:   shiling zhang <shiling99@YAHOO.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   shiling zhang <shiling99@YAHOO.COM>
Organization:   http://groups.google.com/
Subject:   Re: length(compress('')) is 1 ?
Content-Type:   text/plain; charset=ISO-8859-1

So the problem is length(' ')=1;

When not simply goes,

if x=' ' then digits=0; else digits=...;

Just my $0.02.

EdHeaton@WESTAT.COM (Ed Heaton) wrote in message news:<9B501B3774931C469BCCCC021BE5372231E6E0@remailnt2-re01.westat.com>... > Stig, > > A little trick I learned from the ell. This works when the list of > non-wanted characters is longer than the list of wanted characters. > > %let max = 50 ; > %let seed = 574111 ; > Data _null_ ; > /* Create a test string. */ > Length x $&max ; > Do i=1 to &max ; > x = trim(x) || byte( floor( ranUni(&seed) * 256 ) ) ; > End ; > /* Here is your solution. */ > digits = length( "x" || compress( > x > , compress( x , "0123456789" ) > ) ) -1 ; > /* Show the results. */ > Put x= / digits= ; > Run ; > > That solves your task. Others have answered your question about why. > > Ed > > Edward Heaton, Senior Systems Analyst, > Westat (An Employee-Owned Research Corporation), > 1600 Research Boulevard, Room RW-3541, Rockville, MD 20850-3195 > Voice: (301) 610-4818 Fax: (301) 610-5128 > mailto:EdHeaton@westat.com http://www.westat.com > > > -----Original Message----- > From: Stig Eide [mailto:stigeide@YAHOO.COM] > Sent: Friday, March 14, 2003 3:55 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: length(compress('')) is 1 ? > > > I don't get this. > Why is length(compress('')) 1? > I am trying to count number of digits in a text string, > what I came up with was: > number_of_digits = length(string) - length(compress(string,'0987654321')); > > But this don't work because the length of compress('9','9') is 1... > > Anyone have a better idea on how to count number of digits? > > Thanks! > Stig


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