Searching for Historical Analogies
/*--------------------------------------------------------------
SAS Sample Library
Name: smyex04.sas
Description: Example program from SAS/ETS User's Guide,
The SIMILARITY Procedure
Title: Searching for Historical Analogies
Product: SAS/ETS Software
Keys: similarity measures, time-stamped data
PROC: SIMILARITY
Notes:
--------------------------------------------------------------*/
ods graphics on;
data timedata; set sashelp.timedata;
drop volume;
recent = .;
history = volume;
if datetime >= '20AUG2000:00:00:00'DT then do;
recent = volume;
history = .;
end;
run;
proc similarity data=timedata out=_NULL_ outsequence=sequences
outsum=summary;
id datetime interval=dtday accumulate=total
start='27JUL1997:00:00:00'dt
end='21OCT2000:11:59:59'DT;
input history / normalize=absolute;
target recent / slide=season normalize=absolute measure=mabsdev;
run;
data _NULL_; set summary;
call symput('MEASURE', left(trim(putn(recent,'BEST20.'))));
run;
data result; set sequences;
by _SLIDE_;
retain flag 0;
if first._SLIDE_ then do;
if (&measure - 0.00001 < _SIM_ < &measure + 0.00001)
then flag = 1;
end;
if flag then output;
if last._SLIDE_ then flag = 0;
run;
proc timeseries data=result out=_NULL_ crossplot=series;
id datetime interval=dtday;
var _TARSEQ_;
crossvar _INPSEQ_;
run;
proc similarity data=sashelp.applianc out=_null_ outsum=simmatrix;
target units_1--units_24 / measure=mabsdev normalize=absolute;
run;
proc cluster data=simmatrix(drop=_status_) outtree=tree method=ward noprint;
id _input_;
run;
proc tree data=tree horizontal;
run;