Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Forecasting
- /
- How to get a Similarity Matrix

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-25-2013 12:55 PM
(2406 views)

In article *An Introduction to Similarity Analysis Using SAS *by Leonard et al., similarity matrices are introduced in these terms :

Similarity measures can be used to compare several

time sequences to form a *similarity matrix*. This situation usually

arises in *time series clustering*. For example, given *K *time

sequences, a (KxK) symmetric matrix can be constructed whose *ij*th

element contains the similarity measure between the *i*th and *j*th

sequence.

That's a neet idea. However, Proc Similarity (in SAS/ETS 9.3) doesn't accept the same series to be listed as an input and a target sequence. What is the best way to get a similarity matrix with Proc Similarity?

PG

PG

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello -

This example might be useful - additional information can be found here: http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_similarity_sec...

Thanks,

Udo

data tmp;

set sashelp.snacks;

retain Series 0;

if first.product then series+1;

by product;

run;

proc sort data=tmp out=tmp2;

by date;

run;

proc transpose data=tmp2

OUT=tmp3

PREFIX=C_

NAME=reihe

LABEL=Etikett

;

BY Date;

ID series;

VAR QtySold;

run;

proc similarity data=tmp3 out=_null_ outsum=summary;

id date interval=day accumulate=total;

target _numeric_ /normalize=standard measure=mabsdevmax;

run;

data matrix(type=distance);

set summary;

drop _status_;

run;

proc cluster data=matrix outtree=tree method=average;

id _input_;

run;

proc tree data=tree out=result nclusters=4;

id _input_;

run;

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello -

This example might be useful - additional information can be found here: http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_similarity_sec...

Thanks,

Udo

data tmp;

set sashelp.snacks;

retain Series 0;

if first.product then series+1;

by product;

run;

proc sort data=tmp out=tmp2;

by date;

run;

proc transpose data=tmp2

OUT=tmp3

PREFIX=C_

NAME=reihe

LABEL=Etikett

;

BY Date;

ID series;

VAR QtySold;

run;

proc similarity data=tmp3 out=_null_ outsum=summary;

id date interval=day accumulate=total;

target _numeric_ /normalize=standard measure=mabsdevmax;

run;

data matrix(type=distance);

set summary;

drop _status_;

run;

proc cluster data=matrix outtree=tree method=average;

id _input_;

run;

proc tree data=tree out=result nclusters=4;

id _input_;

run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Udo. That's very helpful. I didn't realize that statement INPUT was optional and that in its absence, target sequences would also be considered as input sequences. I hadn't read the clustering example since I have another application in mind.

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.