Hi All,
Below is the sample text and the count of words as result in COUNT column . When using COUNTW function the default delimiter is space , it is applicable for first row , when using the same COUNTW with space as delimiter it is counting Prime minister as two different words , though it is single word. Tried with multiple delimiters and modifiers in COUNTW function , but still could not get the desired result. Can anyone suggest how to count the words in double quotes as single word, even though if there are multiple words present in those quotes or even empty quotes should also be counted as one word.
S.no | TEXT | COUNT |
1 | "Minister" "governor" "President" | 3 words are present |
2 | "Chief Minister" "Prime Minister" "Cabinet Minister\Defence Secretary" "General" "" | 5 words are present including the last empty double quotes |
data have;
name='"Minister" "governor" "President" ';
n=countw(name,' ','q');
output;
name='"Chief Minister" "Prime Minister" "Cabinet Minister\Defence Secretary" "General" "" ';
n=countw(name,' ','q');
output;
run;
data have;
name='"Minister" "governor" "President" ';
n=countw(name,' ','q');
output;
name='"Chief Minister" "Prime Minister" "Cabinet Minister\Defence Secretary" "General" "" ';
n=countw(name,' ','q');
output;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.