SPECTRA Procedure

Example 32.2 Cross-Spectral Analysis

(View the complete code for this example.)

This example uses simulated data to show cross-spectral analysis for two variables X and Y. X is generated by an AR(1) process; Y is generated as white noise plus an input from X lagged 2 periods. All output options are specified in the PROC SPECTRA statement. PROC CONTENTS shows the contents of the OUT= data set.

data a;
   xl = 0; xll = 0;
   do i = - 10 to 100;
      x = .4 * xl  + rannor(123);
      y = .5 * xll + rannor(123);
      if i > 0 then output;
      xll = xl; xl = x;
   end;
run;
proc spectra data=a out=b cross coef a k p ph s;
   var x y;
   weights 1 1.5 2 4 8 9 8 4 2 1.5 1;
run;

proc contents data=b position;
run;

The PROC CONTENTS report for the output data set B is shown in Output 32.2.1.

Output 32.2.1: Contents of PROC SPECTRA OUT= Data Set

The CONTENTS Procedure

Alphabetic List of Variables and Attributes
#VariableTypeLenLabel
16A_01_02Num8Amplitude of x by y
3COS_01Num8Cosine Transform of x
5COS_02Num8Cosine Transform of y
13CS_01_02Num8Cospectra of x by y
1FREQNum8Frequency from 0 to PI
12IP_01_02Num8Imag Periodogram of x by y
15K_01_02Num8Coherency**2 of x by y
2PERIODNum8Period
17PH_01_02Num8Phase of x by y
7P_01Num8Periodogram of x
8P_02Num8Periodogram of y
14QS_01_02Num8Quadrature of x by y
11RP_01_02Num8Real Periodogram of x by y
4SIN_01Num8Sine Transform of x
6SIN_02Num8Sine Transform of y
9S_01Num8Spectral Density of x
10S_02Num8Spectral Density of y


The following statements plot the amplitude of the cross-spectrum estimate against frequency and against period for periods less than 25:

proc sgplot data=b;
   series x=freq y=a_01_02 / markers markerattrs=(symbol=circlefilled);
   xaxis values=(0 to 4 by 1);
run;

The plot of the amplitude of the cross-spectrum estimate against frequency is shown in Output 32.2.2.

Output 32.2.2: Plot of Cross-Spectrum Amplitude by Frequency

Plot of Cross-Spectrum Amplitude by Frequency


The plot of the cross-spectrum amplitude against period for periods less than 25 observations is shown in Output 32.2.3.

proc sgplot data=b;
   where period < 25;
   series x=period y=a_01_02 / markers markerattrs=(symbol=circlefilled);
   xaxis values=(0 to 30 by 5);
run;

Output 32.2.3: Plot of Cross-Spectrum Amplitude by Period

Plot of Cross-Spectrum Amplitude by Period


Last updated: June 19, 2025