ods html close; ods listing; /*--Import data from csv file--*/ proc import datafile='C:\housing.txt' out=housing dbms=csv; /*--Add some forecasted values to the end--*/ data forecast; set housing (where=(date ne .)) end=last; length group $8; retain prev_date prev_index; keep date index group; group='Actual'; if last then do; group='Predict'; dx=date - prev_date; dy=-4; do i=1 to 6; date=prev_date + i*dx; index=prev_index + i*dy; output; end; end; else do; output; prev_date=date; prev_index=index; end; run; /* proc print;run;*/ /*--Events data--*/ data events; input date2 ShortEvent $8-11 Event $12-21 Label $24-34; ylabel=205; datalines; 1890 1913 1914 W1 WW 1 1916.5 W1 WW 1 WW 1 1918 W1 WW 1 1919 1928 1929 D Depression 1934.5 D Depression Depression 1940 D Depression 1940.1 1940.9 1941 W2 WW 2 1944 W2 WW 2 WW 2 1946 W2 WW 2 1947 1975 1976 70 70's Boom 1977.5 70 70's Boom 70's Boom 1979 70 70's Boom 1980 1983 1984 80 80's Boom 1987 80 80's Boom 80's Boom 1989 80 80's Boom 1990 1996 1997 LB Last Boom 2003 LB Last Boom Last Boom 2008 LB Last Boom 2008.1 2010 ; /* proc print;run;*/ data merged; set forecast events; run; /*proc print;run;*/ /*--Basic Forecast Plot--*/ proc template; define statgraph housing1; begingraph; entrytitle "Housing Price Trends in USA"; layout overlay / walldisplay=(fill) pad=(top=20) xaxisopts=(display=(ticks tickvalues line) griddisplay=off offsetmax=0.02 linearopts=(tickvaluesequence=(start=1890 end=2010 increment=10))) y2axisopts=(display=(ticks tickvalues) displaysecondary=(ticks tickvalues) griddisplay=on offsetmin=0.05 offsetmax=0.05 linearopts=(tickvaluesequence=(start=60 end=200 increment=10) thresholdmax=1)); blockplot x=date2 block=event / fillattrs=(color=lightgray) datatransparency=0.5 fillattrs=(color=white) altfillattrs=(color=lightgray) filltype=alternate display=(fill values) valuehalign=center valuevalign=top; seriesplot x=date y=index / yaxis=y2 group=group lineattrs=(thickness=3) name='p' includemissinggroup=false; discretelegend 'p' / location=inside halign=left valign=bottom across=1; endlayout; endgraph; end; run; ods listing; ods graphics / reset width=10in height=6in imagename='Housing_1' antialiasmax=1000; proc sgrender data=merged template=housing1; run; /*--Basic Forecast Plot with Scatter overlay--*/ proc template; define statgraph housing2; begingraph; entrytitle "Housing Price Trends in USA"; layout overlay / walldisplay=(fill) pad=(top=20) xaxisopts=(display=(ticks tickvalues line) griddisplay=off offsetmax=0.02 linearopts=(tickvaluesequence=(start=1890 end=2010 increment=10))) y2axisopts=(display=(ticks tickvalues) displaysecondary=(ticks tickvalues) griddisplay=on offsetmin=0.05 offsetmax=0.05 linearopts=(tickvaluesequence=(start=60 end=200 increment=10) thresholdmax=1)); blockplot x=date2 block=event / fillattrs=(color=lightgray) datatransparency=0.5 fillattrs=(color=white) altfillattrs=(color=lightgray) filltype=alternate display=(fill) valuehalign=center valuevalign=top; scatterplot x=date2 y=ylabel / markercharacter=label yaxis=y2; seriesplot x=date y=index / yaxis=y2 group=group lineattrs=(thickness=3) name='p' includemissinggroup=false; discretelegend 'p' / location=inside halign=left valign=bottom across=1; endlayout; endgraph; end; run; ods graphics / reset width=10in height=6in imagename='Housing_2' antialiasmax=1000; proc sgrender data=merged template=housing2; run; /*--Break up "Boom" labels--*/ data merged2; length label1 $10; set merged; if label="70's Boom" then do; label1="70's"; label2="Boom"; end; else if label="80's Boom" then do; label1="80's"; label2="Boom"; end; else if label="Last Boom" then do; label1="Last"; label2="Boom"; end; else label1=label; run; /*proc print;run;*/ /*--Multi Line Regime Labels--*/ proc template; define statgraph housing3; begingraph; entrytitle "Housing Price Trends in USA"; layout overlay / walldisplay=(fill) pad=(top=20) xaxisopts=(display=(ticks tickvalues line) griddisplay=off offsetmax=0.02 linearopts=(tickvaluesequence=(start=1890 end=2010 increment=10))) y2axisopts=(display=(ticks tickvalues) displaysecondary=(ticks tickvalues) griddisplay=on offsetmin=0.05 offsetmax=0.05 linearopts=(tickvaluesequence=(start=60 end=200 increment=10) thresholdmax=1)); blockplot x=date2 block=event / fillattrs=(color=lightgray) datatransparency=0.5 fillattrs=(color=white) altfillattrs=(color=lightgray) filltype=alternate display=(fill) valuehalign=center valuevalign=top; scatterplot x=date2 y=ylabel / markercharacter=label1 markercharacterattrs=(size=10 weight=bold) yaxis=y2; scatterplot x=date2 y=eval(ylabel-5) / markercharacter=label2 markercharacterattrs=(size=10 weight=bold) yaxis=y2; seriesplot x=date y=index / yaxis=y2 group=group lineattrs=(thickness=3) name='p' includemissinggroup=false; discretelegend 'p' / location=inside halign=left valign=bottom across=1; endlayout; endgraph; end; run; ods graphics / reset width=10in height=6in imagename='Housing_3' antialiasmax=1000; proc sgrender data=merged2 template=housing3; run;