-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtext_analysis.sas
53 lines (48 loc) · 1.03 KB
/
text_analysis.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
*Create sample data;
data random_sentences;
infile cards truncover;
informat sentence $256.;
input sentence $256.;
cards;
This is a random sentence
This is another random sentence
Happy Birthday
My job sucks.
This is a good idea, not.
This is an awesome idea!
How are you today?
Does this make sense?
Have a great day!
;
;
;
;
*Partition into words;
data f1;
set random_sentences;
id=_n_;
nwords=countw(sentence);
nchar=length(compress(sentence));
do word_order=1 to nwords;
word=scan(sentence, word_order);
output;
end;
run;
*Add happiness index and pos;
proc sql ;
create table scored as
select a.*, b.happiness_rank, c.pos, c.pos1
from f1 as a
left join ta.sentiment as b
on a.word=b.word
left join ta.corpus as c
on a.word=c.word
order by sentence, word_order;
quit;
*Calculate sentence happiness score;
proc sql;
create table sentence_sentiment as
select distinct sentence, sum(happiness_rank) as sentiment
from scored
group by id;
quit;