So the problem is length(' ')=1;
When not simply goes,
if x=' ' then digits=0;
Just my $0.02.
EdHeaton@WESTAT.COM (Ed Heaton) wrote in message news:<9B501B3774931C469BCCCC021BE5372231E6E0@remailnt2-re01.westat.com>...
> 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(
> , compress( x , "0123456789" )
> ) ) -1 ;
> /* Show the results. */
> Put x= / digits= ;
> Run ;
> That solves your task. Others have answered your question about why.
> 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?