The mistake in your program was the failure to trim name in the loop.
and your program works. Remember that SAS is a fixed length string
language. One cost is the need for extra TRIMs in many expressions.
However, as others have pointed out a more efficent way is a direct
count = length(compl(name)) - length(compress(name)) ;
From: Jie Qin [mailto:c674010@YAHOO.COM]
Sent: Thursday, March 21, 2002 3:50 PM
Subject: How to get a count of space in a full name?
I want to know how many spaces in a full name which is
composed by first name, middle name, last name and
suffix and separated by space. Here is my raw data and
JACK JOHN SR
WENDY ANN F WILLIAMS
do i=1 to length(name);
if index then count=sum(count,1);
Here is my output:
Obs name count i index
1 9 10 1
2 12 13 1
3 20 21 1
The count is supposed to be:
DAN SMITH 1 (there is 1 space)
JACK JOHN SR 2 (there are 2
WENDY ANN F WILLIAMS 3 (there are 3
What's wrong with my program? Other better solution?
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®