## Loop for correlation between years

Solved
Occasional Contributor
Posts: 15

# Loop for correlation between years

Hi everyone!

Could someone help me to create loop (or different approach) which would compute correlations over years?

have:

year, error, error_L,

1990,0.3,

1991,0.5,0.3,

1992,0.7,0.5,

1993,0.4,0.7,

1994,0.1,0.4,

1995,0.2,0.1,

1996,0.3,0.2,

1997,0.6,0.3,

1998,0.5,0.6,

1999,0.0,0.5,

want:

year, error(t), error_L(t-1), corr (error(t),error(t-1))

1990,0.3,

1991,0.5,0.3,

1992,0.7,0.5,

1993,0.4,0.7,

1994,0.1,0.4,

1995,0.2,0.1,

1996,0.3,0.2,

1997,0.6,0.3,

1998,0.5,0.6,

1999,0.0,0.5,

Thank you in advance!

Accepted Solutions
Solution
‎05-17-2014 10:42 AM
Posts: 1,270

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

I think you can get it by adding one more proc append for pvalues.

proc append base=Rollingpvalues data=p_value force;run;

Thanks,

All Replies
Occasional Contributor
Posts: 15

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

Hi! I have founded and modified the following macro to get the result (please find below).

Could someone be so kind and tell me how still can get p-values for the statistics?

Thank you?

%Macro Mattcorr;

%Do FromYear=1983 %to 2012;

%Let ToYear=%sysevalf(&FromYear.+1);

proc corr data=havenoprint outp=outp(where=(_type_="CORR" and

_Name_="FE") rename=(FE_L=Pearson));

where &FromYear.<=year<=&ToYear.;

var FE FE_L;

run;

data outp;

length Set \$20.;

set outp;

Set="&FromYear.<=year<=&ToYear.";

keep Set Pearson;

run;

proc append base=RollingCorrelations data=outp force;run;

%End;

%Mend;

proc delete data=RollingCorrelations;run;

%Mattcorr;

Occasional Contributor
Posts: 15

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

Let me just mention that p-value is given by:

pvalue=2*(1-probt(abs(corr/sqrt(1-(corr*corr))

*sqrt(n-2)),n-2));

Posts: 1,270

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

Put given below before proc corr

ods output PearsonCorr=p_value;

Occasional Contributor
Posts: 15

## Re: Loop for correlation between years

Do you mean...?

%Macro Mattcorr;

%Do FromYear=1983 %to 2012;

%Let ToYear=%sysevalf(&FromYear.+1);

ods output PearsonCorr=p_value;

proc corr data=Statystka2 noprint outp=outp(where=(_type_="CORR" and

_Name_="FE") rename=(FE_L=Pearson));

where &FromYear.<=year<=&ToYear.;

var FE FE_L;

run;

data outp;

length Set \$20.;

set outp;

Set="&FromYear.<=year<=&ToYear.";

keep Set Pearson p_value;

run;

proc append base=RollingCorrelations data=outp force;run;

%End;

%Mend;

Well I get...

WARNING: Output 'PearsonCorr' was not created.  Make sure that the output object name, label, or

path is spelled correctly.  Also, verify that the appropriate procedure options are used

to produce the requested output object.  For example, verify that the NOPRINT option is

not used.

And still cannot see the p-value

Posts: 1,270

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

Check this

WARNING: Output 'PearsonCorr' was not created.  Make sure that the output object name, label, or

path is spelled correctly. Also, verify that the appropriate procedure options are used

to produce the requested output object.  For example, verify that the NOPRINT option is

not used.

Occasional Contributor
Posts: 15

## Re: Loop for correlation between years

Ok. I get additional set with p-value.

Is it possible to get it in the set RollingCorrelations for each year?

Thank you!

Solution
‎05-17-2014 10:42 AM
Posts: 1,270

## Re: Loop for correlation between years

Posted in reply to MattvanPallen

I think you can get it by adding one more proc append for pvalues.

proc append base=Rollingpvalues data=p_value force;run;

Thanks,

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 7 replies
• 312 views
• 3 likes
• 2 in conversation