Fluorite | Level 6

## Computing cross correlation for various time stamps

Hello everybody.

I have a data set which contains the following variables: date, firm and abnormal return. I attached a sample file.

I want to compute the cross correlation of the returns between the firms at each time stamp and then compute a mean cross correlation for the whole time period. I am a beginner in SAS and guess I need matrix notation but already got stuck on converting my data into a matrix.

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: Computing cross correlation for various time stamps

Cross-correlations are computed over multiple time periods (ie. lags) rather than over a single time point.  Also, one typically has a single dependent variable and multiple potential inputs, and a CCF analysis is performed to help you see how correlated other potential inputs are with that dependent variable.

I wonder if a similarity analysis might be more in line with what you need…

5 REPLIES 5
Opal | Level 21

## Re: Computing cross correlation for various time stamps

If you have SAS/ETS you could use: http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_timeseries_sec...

Art, CEO, AnalystFinder.com

Fluorite | Level 6

## Re: Computing cross correlation for various time stamps

Yes, I also found this procedure and have tried it but since there is very few explanations on syntax online I don't know how to implement it.

Tourmaline | Level 20

## Re: Computing cross correlation for various time stamps

I'm not entirely sure what your desired result looks like here?

Perhaps like this?

``````proc sort data= ret.abnormalreturn out=abnormalreturn;
by date;
run;

proc transpose data=abnormalreturn out=abnormalreturn_wide(drop=date);
by date;
id firm;
var ar;
run;

ods select PearsonCorr;
proc corr data=abnormalreturn_wide noprob outp=OutCorr
nomiss;
var _numeric_;
run;``````
Fluorite | Level 6

## Re: Computing cross correlation for various time stamps

Hi draycut,

i'm not sure if this does what i want since i need to calculate cross correlation and not only correlations.

I figured something out this morning and not sure if this is correct:

``````proc sort data=WORK.abnormalreturn out=WORK.SORTTempTableSorted;
by Date Firm;
run;

proc transpose data=WORK.SORTTempTableSorted out=WORK.ARCor;
var ar;
id Firm;
by Date;
run;

proc delete data=WORK.SORTTempTableSorted;
run;

proc timeseries data=ARcor outcrosscorr=crosscor;
var _all_ ;
id date interval=weekday;
crosscorr lag n ccf;
run;

proc means data=crosscor mean noprint;
output out=cormean (drop=_type_ _freq_)
mean(ccf)=roh ;
run;``````

Does this lead to the same output as the code you suggested? And if this is wrong and I should use your code, how would I compute a mean across all the correlations since their not in the same column?

SAS Super FREQ

## Re: Computing cross correlation for various time stamps

Cross-correlations are computed over multiple time periods (ie. lags) rather than over a single time point.  Also, one typically has a single dependent variable and multiple potential inputs, and a CCF analysis is performed to help you see how correlated other potential inputs are with that dependent variable.

I wonder if a similarity analysis might be more in line with what you need…

Discussion stats
• 5 replies
• 2747 views
• 1 like
• 4 in conversation