0

I need to calculate the correlation for each symbol and day. And I also need to count the number of symbols and days for which the correlation coefficient is significantly different from 0.

Below is my code. Now I have to look at the output and count manually but there must be an easier way. How should I change this code to make this possible? Thank you.

proc corr data=sourceh.zmetricsbysymbol ;
by symbol day; 
var zbuy zsell;
run;
Betsy B
  • 77
  • 2
  • 11
  • Your first step is to save the correlations to a dataset, then you can filter the table. You can see how to save table in this example. http://stackoverflow.com/q/30896668/1919583 – Reeza Mar 12 '16 at 02:22

1 Answers1

1

If you're only looking at two variables, then it's relatively straightforward. As mentioned in the link above, capture the table using ODS OUTPUT/TABLE to capture table. Since it's two variables, its a symmetric matrix, so delete the first entry and look at the values and flag them as required.

Here's a worked example. PS in the future please provide sample data or use a dataset from SASHELP library to demonstrate your problem.

proc sort data=sashelp.cars out=cars;
by make;
run;

ods select PearsonCorr;
proc corr data=cars;
by make;
var mpg_highway invoice;
ods output PearsonCorr=corr_table;
run;

data corr_table;
set corr_table;
by make;
if first.make;
if PInvoice< 0.05 then flag_significant=1;
else flag_significant=0;
run;

proc print data=corr_table;
run;
Reeza
  • 20,510
  • 4
  • 21
  • 38
  • Thanks so much. The link you sent in your comment helped me fix it. The code is also very useful to understand. – Betsy B Mar 12 '16 at 18:42