BookmarkSubscribeRSS Feed
Mgarret
Obsidian | Level 7

Hi All,

I'm trying to right a program which will sum up all the unique words in a variable -  this needs to be not case sensitive.  I need to use just Base SAS.

CONTENT
signs that I might be experiencing Candida? A. Here is our list of 100 Common Candida Symptoms associated with systemic. Use zyrtec
i    a week of sttn.. about 3 weeks ago.. LO had bad allergies so he had to take some zyrtec but he slept sooo good
Allergy Aid Cleansing Expert services Are Necessary Some folks are incapable of having a great night's sleep

So the output I'm looking for is something like this (this is not the full list):

Word Count
zyrtec2
Some2
of3
I2
he2
had 2
experiencing1
Common1
Cleansing1
Candida1
a2

Is there a way to write a do loop? It would obviously way too difficult  to you just string functions to do this.

Any assistance is greatly appreciated.

Thanks! 

1 REPLY 1
Reeza
Super User

A few functions - countw, compress, scan, and lowcase can get you pretty far.

data words;

set have;

num_words=countw(sentence);

do i=1 to num_words;

word=lowcase(compress(scan(sentence, i), , 'ka'));

output;

end;

keep word;

run;

proc freq data=words;

table word;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1711 views
  • 1 like
  • 2 in conversation