BookmarkSubscribeRSS Feed
Barite | Level 11

Suppose we have two time-series, X1 and X2.  I'm wondering if SAS has a way of showing if the two series are in-sync, or in-phase, vs. out of sync/phase.


Let's say we want to execute some action when the sync of X1, X2 is maximally moving in the same direction.


We have to be able to track the sync/phase.  Have a measure thereof.


Seems what I am seeking is like a 'moving correlation' -- which takes into account the previous so many days of data.


Any thoughts greatly appreciated.


Nicholas Kormanik


Jade | Level 19

I've always been disappointed that PROC EXPAND only does univariate series transformations.  That's why in the useful paper mentioned by @KatScott you have to prepare the dataset (e.g. create product X1_2=x1*x2) prior to PROC EXPAND, which of course is followed by a PROC CORR.


It might be a better idea to skip the proc expand, as in:  


data need (drop=_:) view=need ;
  set have;
  if _n_=1 then do;
    declare hash h (dataset:'have(obs=0)',ordered:'a');
    declare hiter hi ('h');

  window_close_date=date ;
  format window_close_date date9. ;

  if _date&winsize^=. then h.remove(key:_date&winsize);

  if _n_>=&winsize then do _rc=hi.first() by 0 until (^=0);

proc corr data=need noprint  out=correlations;
  by window_close_date ;
  var x y;

Dataset view NEED simply creates a set of records for each window.  In the above instance the window size is 21, and is identified by the variable WINDOW_CLOSE_DATE.  Each WINDOW_SIZE_DATE will have 21 records ( and therefore most records will appear in 21 windows) in NEED.   For a large windows size, that's a lot of records, but disk activity is kept to a minimum by generating NEED as a data set VIEW, not a data set FILE.  

The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets




Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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
  • 2 replies
  • 1 like
  • 3 in conversation