Programming the statistical procedures from SAS

Cross Correlation using array of macro series

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Cross Correlation using array of macro series

Dear all,

I am new to SAS. I would appreciate it if anyone helps me. I have to write a code that calculates a cross correlation between one fixed variable and 2000 other macro variables and put it all in a table. To do it manually will take a lot of time. How can I create an array of macro variables and then use proc corr command in the loop? Thank you in advance. 

Yelena

 


Accepted Solutions
Solution
‎04-01-2016 01:46 PM
Grand Advisor
Posts: 16,908

Re: Cross Correlation using array of macro series

You can't use arrays in Proc corr. You can specify a variable list.

 

For example if you use double dashes it includes all variables between the indicated variables. Given your code this is probably what you're looking for:

 

ods graphics on;
proc corr data=merged_macro2 plots=matrix(histogram);
var v1;
with &list
run;
ods graphics off;

View solution in original post


All Replies
Grand Advisor
Posts: 16,908

Re: Cross Correlation using array of macro series

[ Edited ]

Please post some sample data and output.

Proc corr allows lists of variables so I'm not sure why you're using a macro. You can avoid listing variables if you have naming conventions. Anyways, we need samples of what you're looking for to help. 

 

 

proc corr data=have;
var v1;
with v2 - v2000;
run; 
Contributor
Posts: 41

Re: Cross Correlation using array of macro series

Thank you, Reeza. My data looks like this:

Date                           v1       rGDP       nGDP

30Sep2000               50        0.5             3.1

31Dec2000                30       2.3             4.5

31Mar2001                20        2.1            1.4

 

I fix v1 but want to run cross correlation for other macro variables, like real GDP (rGDP), nominal GDP (nGDP), etc. I tried to create a list of variables separately and then use array but for some reason my code does not run. 

 

data merged_macro2;
set &merged_macro1;
array macro(*) &list;

do i = 1 to dim(macro);
macro(i) = macro(i);
end;
run;

 

 

ods graphics on;
proc corr data=merged_macro2 plots=matrix(histogram);
var variable(1);
with macro(2) - macro(dim(macro));
run;
ods graphics off;

Solution
‎04-01-2016 01:46 PM
Grand Advisor
Posts: 16,908

Re: Cross Correlation using array of macro series

You can't use arrays in Proc corr. You can specify a variable list.

 

For example if you use double dashes it includes all variables between the indicated variables. Given your code this is probably what you're looking for:

 

ods graphics on;
proc corr data=merged_macro2 plots=matrix(histogram);
var v1;
with &list
run;
ods graphics off;
Contributor
Posts: 41

Re: Cross Correlation using array of macro series

Thank you, Reeza, and everyone, who helped me solve this problem. The code is:

 


%let macro = ub.test;
%let list =
GDP
FE
;

ods graphics on;
proc corr data=ub.test plots=matrix(histogram);
var LGD;
with &list;
run;
ods graphics off;

Grand Advisor
Posts: 10,052

Re: Cross Correlation using array of macro series

I am a little concerned about "2000 macro variables" as proc corr doesn't do much with "macro variables" unless they resolve to data set variable names or proc options.

 

If the macro variables are data set variable names I would suggest something like;

 

proc corr data = yourdataset ;

   var TheOneVariableName;

   WIth _numeric_;

run;

 

that would do correlations between your variable and all numeric variables in the data set.

 

Or you need to provide a lot more detail about what you are starting with and the desired result.

Contributor
Posts: 41

Re: Cross Correlation using array of macro series

Thank you very much for your quick reply. I will try to test it. 

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 354 views
  • 0 likes
  • 3 in conversation