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.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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