-
Notifications
You must be signed in to change notification settings - Fork 2
/
01-Simple.sas
executable file
·100 lines (88 loc) · 3.22 KB
/
01-Simple.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Program for
Wicklin, Rick (2023) "Ten Tips for Creating Effective Statistical Graphics"
presented at multiple SAS conferences, including SAS Innovate 2024 in Las Vegas.
Cite as
Wicklin, Rick (2023) "10 tips for creating effective statistical graphics."
_The DO Loop_ blog. Published December 6, 2023.
Accessed 01MAR2024
https://blogs.sas.com/content/iml/2023/12/06/10-tips-statistical-graphics.html
*/
title; footnote; ods graphics / push;
/* 1. Simpler Is Better */
/* Replace radar plot by a "butterfly chart" or a chart of differences
https://blogs.sas.com/content/iml/2013/08/21/comparing-two-groups-graphically.html
*/
data Debate2012;
input Category $15. Obama Romney;
datalines;
Individualism 47 53
Directness 49 51
Talkativeness 49 51
Achievement 45 55
Perceptual 44 56
Quantitative 36 64
Insight 47 53
Causation 59 41
Thinking 52 48
Certainty 56 44
Sophistication 51 49
Collectivism 56 44
;
data Long; /* transpose the data from wide to long */
set Debate2012;
Candidate = "Obama "; Value = Obama; output;
Candidate = "Romney"; Value = Romney; output;
drop Obama Romney;
run;
/* display a horizontal bar chart */
title "2012 US Presidential Debates";
title2 "Linguistic Style Indexed Across Three Debates";
footnote justify=left "Data from http://blog.odintext.com/?p=179";
proc sgplot data=Long;
hbar Category / response=Value group=Candidate groupdisplay=stack;
refline 50 / axis=x lineattrs=(color=black);
yaxis discreteorder=data;
xaxis label="Percentage" values=(0 to 100 by 10);
run;
/* Two problems:
1. The categories are not sorted in a useful order
2. To contrast two groups, plot the DIFFERENCE between the groups, rather than the absolute quantities.
*/
data DebateDiff;
set Debate2012;
label Difference = "Percentage Difference: Romney - Obama"
DifferenceOR = "Percentage Difference: Obama - Romney";
DifferenceRO = Romney - Obama;
DifferenceOR = -DifferenceRO;
Difference = DifferenceRO;
if Difference>0 then Advantage = "Romney";
else Advantage = "Obama ";
run;
proc sort data=DebateDiff; /* sort categories by difference */
by Difference;
run;
/* show the raw categories again, but sorted */
data DiffLong; /* transpose the data from wide to long */
set DebateDiff;
Candidate = "Obama "; Value = Obama; output;
Candidate = "Romney"; Value = Romney; output;
drop Obama Romney;
run;
title "2012 US Presidential Debates";
title2 "Linguistic Style Indexed Across Three Debates";
footnote justify=left "Data from http://blog.odintext.com/?p=179";
proc sgplot data=DiffLong;
hbar Category / response=Value group=Candidate groupdisplay=stack;
refline 50 / axis=x lineattrs=(color=black);
yaxis discreteorder=data;
xaxis label="Percentage" values=(0 to 100 by 10);
run;
title2 "Linguistic Style Differences Indexed Across Three Debates";
proc sgplot data=DebateDiff;
hbar Category / response=DifferenceOR group=Advantage;
refline 0 / axis=x;
yaxis discreteorder=data;
xaxis grid;
keylegend / position=bottomright location=inside title="Candidate" across=1;
run;
title; footnote; ods graphics / pop;