BookmarkSubscribeRSS Feed
Jianan_luna
Obsidian | Level 7

For this question, I cannot make sense the answer for wordnum. I think it should be 3. Can you please help me to figure it out? Thanks so much

Jianan_luna_0-1597784869379.png

 

3 REPLIES 3
SASKiwi
PROC Star

There are 4 words in the text string - 'US' counts as a word too. COUNTW counts words.

ballardw
Super User

COUNTW without any modifiers and just the string will count everything separated by the default list of delimiters as a word. Since comma and space are some of the default delimiters when you do

 

Countw('Australia, Italy, Austria, US') then the first word is Australia, second is Italy, third is Austria and 4th is US.

In this code:

data example;
   x ='123,ABC, six, B, Pdq, {, #';
   count = countw(x);
   put count=;
run;

The result is 7 because anything delimited by comma and space counts as a "word" even the single characters { and # unless you modify the list of delimiters.

In this

data example;
   x ='123,ABC, six, B, Pdq, {, #';
   count = countw(x,'B');
   put count=;
run;

the 'B' in the countw function modifies the list of delimiters and in this case will use only the letter B as a delimiter. So the "words" become : "123,A"   "C, six, " and  ", Pdq, {, #".

 

 

 

 

 

Jianan_luna
Obsidian | Level 7
Thanks so much, for the second example, the value of count is 3, right?

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
  • 3 replies
  • 956 views
  • 0 likes
  • 3 in conversation