/* electric.sas */ options ls=72 ps=60; data elec; infile 'electric.dat'; input date day $ temp load; period = 'weekday'; if day = 'Sun' then period = 'sun'; if day = 'Sat' then period = 'sat'; indicate = period; if period = 'sun' then indicate = 'u'; if date=5 then period = 'sun'; if date=5 then indicate = 'hol'; x0=1; week = (period = 'weekday'); sat = (period = 'sat'); sun = (period = 'sun'); end = sat+sun; weektemp = temp*week; sattemp = temp*sat; suntemp = temp*sun; proc plot data=elec; plot load*temp=indicate; title 'electricity load data'; proc print data=elec; var date day period weektemp sattemp suntemp; proc print data=elec; var date day period week sat sun; proc glm data=elec; model load=week sat sun weektemp sattemp suntemp/ noint ss1 ss2; contrast 'parallel lines' weektemp 1 sattemp -1, sattemp 1 suntemp -1; output out=new1 predicted=yhat residual=resid lcl=clpl ucl=clpu lclm=clml uclm=clmu; title '3 separate lines: weekday, Saturday, Sunday'; proc print data=new1; var period date temp load clml clmu clpl clpu yhat resid; proc plot data=new1; plot resid*temp=indicate / vref=0; plot resid*date=indicate / vref=0; proc univariate data=new1 plot normal; var resid; proc rank data=new1 normal=blom out=new1r; var resid; ranks normsc; proc plot data=new1r; plot resid*normsc; proc glm data=elec; model load=week sat sun temp/noint ss1 ss2; estimate 'dist betw week sat' week 1 sat -1; estimate 'dist betw sat sun' sat 1 sun -1; output out=new2 predicted=yhat residual=resid lcl=clpl ucl=clpu lclm=clml uclm=clmu; title '3 parallel lines: weekday, Saturday, Sunday'; proc print data=new2; var period date temp load clml clmu clpl clpu yhat resid; proc plot data=new2; plot resid*temp=indicate / vref=0; plot resid*date=indicate / vref=0; proc univariate data=new2 plot normal; var resid; proc rank data=new2 normal=blom out=new2r; var resid; ranks normsc; proc plot data=new2r; plot resid*normsc; proc glm data=elec; model load=week end temp/noint ss1 ss2 clparm; estimate 'dist betw week end' week 1 end -1; output out=new3 predicted=yhat residual=resid lcl=clpl ucl=clpu lclm=clml uclm=clmu; title '2 parallel lines: weekday, weekend'; proc print data=new3; var period date temp load clml clmu clpl clpu yhat resid; proc plot data=new3; plot resid*temp=indicate / vref=0; plot resid*date=indicate / vref=0; proc univariate data=new3 plot normal; var resid; proc rank data=new3 normal=blom out=new3r; var resid; ranks normsc; proc plot data=new3r; plot resid*normsc; proc glm data=elec; model load=x0 temp/noint ss1 ss2; output out=new4 predicted=yhat residual=resid lcl=clpl ucl=clpu lclm=clml uclm=clmu; title 'single line for all days'; proc print data=new4; var period date temp load clml clmu clpl clpu yhat resid; proc plot data=new4; plot resid*temp=indicate / vref=0; plot resid*date=indicate / vref=0; run;