code segmented regression sas
TRANSCRIPT
-
8/19/2019 Code Segmented Regression SAS
1/5
SAS Code
/* Set the graphics environment */
goptions reset=all border cback=white htitle=12pt htext=10pt;
FILENAME REFFILE "/home/suryachaitanya1/MyFolder/Switch_Data_Case.csv";
/* Segmented Regression analysis in SAS */
data WORK.TRAFFIC ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile REFFILE delimiter = ',' MISSOVER DSD firstobs=11 ;
informat VAR1 anydtdtm40. ;
informat VAR2 18.;
informat VAR3 18.;informat VAR4 18.;
informat VAR5 18.;
format VAR1 datetime. ;
format VAR2 18.;
format VAR3 18.;
format VAR4 18.;
format VAR5 18.;
input
VAR1
VAR2 $VAR3 $
VAR4 $
VAR5 $
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable
*/
run;
data traffic(rename = (VAR1 = Date VAR2 = Inbound VAR3=col2_cdefa VAR4=Outbound VAR5
=col4_cdeff));
set traffic;
run;
data traffic;
set traffic;
total_traffic=Inbound + Outbound;
run;
-
8/19/2019 Code Segmented Regression SAS
2/5
data traffic2;
set traffic;
if datepart(Date) in ('13AUG15'd,'05NOV15'd) then do;
total_traffic = .;
end;run;
data traffic2;
set traffic2;
if _n_ =1 then do;
time = 1;
retain time;
end;
else do;
time = time + 1;retain time;
end;
if datepart(Date) ge '27Aug15'd then do;
event = 1;
end;
else do;
event = 0;
end;
run;
data traffic2;
set traffic2;
if datepart(date) eq '27Aug15'd then do;
time_from_event = 0;
retain time_from_event;
end;
if datepart(date) gt '27Aug15'd then do;
time_from_event = time_from_event + 1;
retain time_from_event;
end;
if datepart(date) lt '27Aug15'd then do;
time_from_event = 0;
end;
run;
data traffic2;
set traffic2;
-
8/19/2019 Code Segmented Regression SAS
3/5
time2= datepart(date)-'27Aug15'd;
run;
%macro traffic(n=);
Proc Autoreg Data = traffic2 outest= param_estimates_autoreg;model &n = time2 event time_from_event/dwprob
run;
proc arima data=traffic2;
identify var=&n stationarity=(dickey=0);
quit;run;
Proc Autoreg Data = traffic2 outest= param_estimates_autoreg;
model &n = time2 event time_from_event/
method = ml NLAG = 6 Backstep DWPROB LOGLIKL;output out = out1 p=pvar r = rvar;
run;
%mend;
%traffic(n=total_traffic);
*%traffic(n=InBound);
*%traffic(n=OutBound);
R Code
install.packages("zoo")
install.packages("fpp")
install.packages("forecast")
library(plyr)
library(zoo)
library(fpp)
library(forecast)
# Load Data Into R
switchcase
-
8/19/2019 Code Segmented Regression SAS
4/5
# This is with out the first 9 rows
switchcase2
-
8/19/2019 Code Segmented Regression SAS
5/5
stationarity