hi!
I have a data ( number of crashes ). I used interrupted time series to show the effect of speed camera that introduced at time=49
I want to plot in one graph as in the Figure1a in the link http://www.cdc.gov/pcd/issues/2013/12_0268.htm
30 1
26 2
39 3
44 4
35 5
20 6
27 7
67 8
25 9
39 10
69 11
74 12
45 13
41 14
50 15
67 16
55 17
77 18
41 19
38 20
38 21
46 22
45 23
62 24
60 25
62 26
49 27
60 28
78 29
69 30
64 31
86 32
68 33
53 34
59 35
56 36
68 37
57 38
59 39
101 40
63 41
90 42
92 43
64 44
77 45
69 46
82 47
70 48
63 49
66 50
78 51
94 52
88 53
62 54
77 55
92 56
76 57
55 58
70 59
54 60
76 61
58 62
58 63
79 64
77 65
79 66
;
Create two additional variables that mimic the original data, for use in SGPLOT REG statements.
data have;
input crash_count time;
if time < 49 then y1 = crash_count; * y1 missing when time >=49;
if time >= 49 then y2 = crash_count; * y2 missing when time < 49;
datalines;
30 1
26 2
39 3
44 4
35 5
etc...
proc sgplot data=have;
series x=time y=crash_count / markers markerattrs=(symbol=circlefilled) ;
reg x=time y=y1 / nomarkers lineattrs=(pattern=dot color=black) legendlabel='Trendline Pre-49';
reg x=time y=y2 / nomarkers lineattrs=(pattern=dash color=black) legendlabel='Trendline Post-49';
keylegend / across=1 location=inside;
run;
Note: The REG statement has no option for extending a fit line (such as the pre-49 dotted line) from left edge to right edge.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.