BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
keen_sas
Quartz | Level 8

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 
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Ksharp
Super User
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;
keen_sas
Quartz | Level 8
Thank you , not sure how i missed this "q" Modifier.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1641 views
  • 0 likes
  • 2 in conversation