forked from statgeek/SAS-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgplot_intro_example
81 lines (66 loc) · 1.86 KB
/
sgplot_intro_example
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
proc sort data=sashelp.iris out=iris;
by species;
run;
/*SGScatter sample*/
proc sgscatter data=iris;
By Species;
matrix petallength petalwidth sepallength / ellipse=(type=mean)
diagonal=(histogram kernel);
run;
/*Bar Chart*/
data bar_chart;
input question answer $ value;
cards;
1 Yes 98
1 No 2
;
run;
proc sgplot data=bar_chart;
hbar answer / response=value stat=SUM;
label answer='Response' value='Percent';
run;
quit;
*Change to stacked bar chart;
proc sgplot data=bar_chart;
hbar question / group=answer response=value stat=SUM groupdisplay=stack
CATEGORYORDER=RESPDESC;
label answer='Response' value='Percent';
xaxis min=96;
yaxis display=none;
run;
quit;
*Customize the axis - within procedure changes, add title;
proc sgplot data=bar_chart;
hbar question / group=answer response=value stat=SUM groupdisplay=stack
CATEGORYORDER=RESPDESC;
label answer='Response' value='Percent';
xaxis min=96;
yaxis display=none;
title 'Does truncating an axis lead to misleading interpretations';
run;
*Switch graph types:
hbar to vbar
switch y vs x axis statements;
proc sgplot data=bar_chart;
vbar question / group=answer response=value stat=SUM groupdisplay=stack
CATEGORYORDER=RESPDESC;
label answer='Response' value='Percent';
yaxis min=96;
xaxis display=none;
title 'Does truncating an axis lead to misleading interpretations';
run;
*Broken axis instead?;
proc sgplot data=bar_chart;
vbar question / group=answer response=value stat=SUM groupdisplay=stack
CATEGORYORDER=RESPDESC;
label answer='Response' value='Percent';
yaxis ranges=(0-10 90-100);
/*specify the ranges for broken range*/
xaxis display=none;
title 'Broken Axis instead?';
run;
*Line Graph;
proc sgplot data=sashelp.stocks;
where stock = 'IBM';
series x=date y= open;
run;quit;