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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: