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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.