BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yelena
Fluorite | Level 6

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
Reeza
Super User

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; 
yelena
Fluorite | Level 6

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;

Reeza
Super User

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;
yelena
Fluorite | Level 6

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;

ballardw
Super User

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.

yelena
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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