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
- /
- Using Cross Correlation to determine time delay between two signals

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 03-02-2018 02:48 AM
(3163 views)

What I have is two signals in time (x=time in seconds, y=Force) and they are lagged (see graph bellow). The lag is unknown to me and I have more than 5000 of this pair of curves. I need to align all this pairs or curves to enable other posterior analysis.

To do that, I would normally use the cross correlation method to find the the point in time where the two signals are best aligned in seconds . After I have the this optimal set point, I can use this number to correct one of the time series and make them match.

The problem is that I never did this in sas and I was wondering if there is a procedure that I can use or I need to code this in sas base from scratch myself. I google quite a bit and I'm not sure if what I call a cross correlation could be done with proc timeseries, or proc ARIMA in EG or even with some TS node in EM.

I would take any recommendation regardless of it is the name of a procedure, a sas base program, or an em node.

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions

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

You can use PROC TIMESERIES to compute crosscorrelations. You need to use the CROSSCORR and CROSSVAR statements. Here is simple example.

```
data temp;
call streaminit(123);
do i=1 to 103;
x = rand("Uniform");
y = lag3(x);
if i > 3 then output;
end;
drop i;
run;
proc timeseries data = temp crossplot=all outcrosscorr=outcrosscorr;
crosscorr lag n ccov ccf ccfstd;
var x;
crossvar y;
run;
```

I am not sure exactly what the purpose of your analysis is, but you may want to look also at the SIMILARITY procedure. It allows you to compute a distance matrix between series using time warping rather than cross-correlation.

6 REPLIES 6

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

You can call PROC TIMESERIES to compute cross correlation of two time series. See the following for a simple code example:

proc timeseries data=sashelp.pricedata out=_NULL_ outcrosscorr=crosscorr;

crosscorr _ALL_ / nlags=12;

id date interval=month;

var sale price;

by region line product;

run;

You can also check http://support.sas.com/documentation/cdl/en/etsug/66840/HTML/default/viewer.htm#etsug_timeseries_syn... for more details on the PROC and related functionalities.

Check out the time series and forecasting tasks in SAS Studio! They provide an easy point-and-click interface for Time Series Data Preparation, Time Series Exploration, and Time Series Modeling and Forecasting.

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

You can use PROC TIMESERIES to compute crosscorrelations. You need to use the CROSSCORR and CROSSVAR statements. Here is simple example.

```
data temp;
call streaminit(123);
do i=1 to 103;
x = rand("Uniform");
y = lag3(x);
if i > 3 then output;
end;
drop i;
run;
proc timeseries data = temp crossplot=all outcrosscorr=outcrosscorr;
crosscorr lag n ccov ccf ccfstd;
var x;
crossvar y;
run;
```

I am not sure exactly what the purpose of your analysis is, but you may want to look also at the SIMILARITY procedure. It allows you to compute a distance matrix between series using time warping rather than cross-correlation.

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

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

BTW, I forget to mention that if you use SAS Studio, the forecasting tasks provide an easy point-and-click interface that generates code for this type of analysis and much more.

I should put this sentence as my signature

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

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

Let's see how my signature looks now.

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.