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
There are 4 words in the text string - 'US' counts as a word too. COUNTW counts words.
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, {, #".
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.