DATA Step, Macro, Functions and more

Perform Sentiment Analysis Using Base +advanced Sas.

Reply
Contributor
Posts: 23

Perform Sentiment Analysis Using Base +advanced Sas.

[ Edited ]

I have to analyize a tweet for example : 

This is not good at all. 

 

we have a table which includes words with there polarity values.

eg 
Word     polarity 

good       +3

not good  -3

 

When i pass this through code i should get a polarity of tweet as -3 and not +3.

"good" has a positive polarity but since a "not" comes before it the whole  meaning changes.

Help me out with this one.

 

 

 

 

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

What's the ngram of your look up table? 

Contributor
Posts: 23

Re: Perform Sentimental Analysis Using Base +advanced Sas.

I am not clear with what exactly ngram refers to.

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

# of words per phrase 

 

good - 1-gram

not good 2-gram

really not good 3-gram

 

What is the max ngram of your lookup table?

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Also, what's 'Advanced SAS'? Do you have EM with text analytics? 

Contributor
Posts: 23

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Advanced SAS using proc sql or macros. and No i don't have em with text analytics.

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.


Reeza wrote:

# of words per phrase 

 

good - 1-gram

not good 2-gram

really not good 3-gram

 

What is the max ngram of your lookup table?




 

Contributor
Posts: 23

Re: Perform Sentimental Analysis Using Base +advanced Sas.

3

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

A data step is all you need. 

 

1. Create a format for lookup table

2. Break a sentence into words. Since these are tweets you have a limit of words so splitting into an array should be easy enough. CountW will tell you how many words. 

3a. Loop through each word for 1 gram, apply format and if found output score. 

3b. Loop through again for 2 gram, apply format and if found output score

3c. 3a/3b for 3 gram. 

 

 

Contributor
Posts: 23

Re: Perform Sentimental Analysis Using Base +advanced Sas.

ya i was able to get to the part of splitting words. bt i still didnt get how to apply the n gram logic. 
It would be great if you can help me with a sample code for above example.

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

Sample data?

Contributor
Posts: 23

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Here one is attached file containing 5 tweets and the other file has around 2400 words with their polarity scores.

Attachment
Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

I'm not downloading a zip file. Most won't either. 

Add as plain text into your post, ideally as a data step

 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

Super User
Posts: 19,865

Re: Perform Sentimental Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

The question and code here are relevant, but the techniques may be beyond your programming skills. I'm a proponent of understanding your code. 

 

https://communities.sas.com/t5/Base-SAS-Programming/Big-Data-Cartesian/m-p/288303/highlight/true#M59...

Trusted Advisor
Posts: 1,584

Re: Perform Sentiment Analysis Using Base +advanced Sas.

Posted in reply to wizkid2050

Does your polarity table contains priority of checking words ?

Which columns do you have in this polarity table ? Can you add columns to it ?

 

Using a simple data step with indexw() function can do the work,

here, without using a polarity table, but just coding your example:

 

data _NULL_;

     text = 'This is not good at all. ';

     if indexw(text, 'not good') > 0 then polarity=-3; else  /* priority 1 */

     if indexw(text,'good') > 0 then polarity = 3;                /* priority 2 */

     put polarity=;

run;

Ask a Question
Discussion stats
  • 14 replies
  • 519 views
  • 0 likes
  • 3 in conversation