I think sentiment analysis is usually a score along a continuum, with one end of the scale registered as negative and the other as positive, and the midrange is simply neutral. In this model, discrete emotions like "happy" "sad" "angry" are not part of the ruling.
This interesting paper from the Midwest SAS Users Group describes how you might achieve something close to what you want by relying on catchphrases. Emoticons or emojis may also play a role. See this paper and this blog post. In the end, this might be a machine learning problem, where you build a model using training data where you already know the conveyed emotion, and you then score your test data based on what the algorithm has learned from those patterns.
Update: a few more thoughts based on some internal discussion here at SAS:
SAS software that supports NLP (natural language processing) and sentiment analysis will score text for "general feeling or opinion", not emotion (which is different). Consider a tweet that features the word ‘position’ to highlight that you are ‘for or against’ something. You can have a positive attitude towards it or a negative attitude. But, the algorithms do not trying to distinguish if you are positive because you are happy, content, joyful or just peaceful, or if you are negative about something because you are sad, angry, or nervous.
There are no real dependable cues to a person’s emotional state in text, partially because many people do not understand their own emotions well enough to depict or name them, even if you asked them to. (This is obvious if you've ever been part of a text-message conversation that results in hurt feelings because one or both parties misreads emotions -- part of the human experience now, it seems.)
Consider these examples:
- "My wife is sorry that we don't yet have a Wegmans in the neighborhood." - maybe sad for my wife, but positive for the Wegmans brand
- "Yay! I haven't stopped celebrating since the Patriots lost last week!" - maybe happy for me, but negative for the Patriots. (... and yes, I know they actually won last week. It's just an example.)