turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Loop for correlation between years

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-17-2014 05:23 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 10:42 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 08:49 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 09:08 AM

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));

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 09:15 AM

Put given below before proc corr

ods output PearsonCorr=p_value;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to stat_sas

05-17-2014 09:26 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 09:32 AM

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.**

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to stat_sas

05-17-2014 10:21 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MattvanPallen

05-17-2014 10:42 AM

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

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

Thanks,