BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
EBB
Obsidian | Level 7 EBB
Obsidian | Level 7

 

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.

 

crosscorrelation.PNG

 

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
mitrov
SAS Employee

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. 

View solution in original post

6 REPLIES 6
Puwang
Obsidian | Level 7

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.

mitrov
SAS Employee

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. 

EBB
Obsidian | Level 7 EBB
Obsidian | Level 7

Thanks for that! I also thought about DTW but it does not fit to what I need to do afterwards with the data.  

mitrov
SAS Employee

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 Smiley Happy

mitrov
SAS Employee

Let's see how my signature looks now. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Discussion stats
  • 6 replies
  • 2737 views
  • 1 like
  • 3 in conversation