<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: correlation among variables with macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/correlation-among-variables-with-macro/m-p/685231#M24286</link>
    <description>&lt;P&gt;You have only one variable listed in the VAR statement of PROC CORR each time the macro runs. SAS can't read your mind and figure out you really want four variables in the PROC CORR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do a lot of debugging yourself, and identify this problem, if you place the command &lt;FONT face="courier new,courier"&gt;options mprint;&lt;/FONT&gt; at the beginning of your program, run it again, and look at the LOG and see what code has been generated by your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need all four of your variables in the VAR statement to get a correlation matrix. To get this, you will need to merge four data sets together. Then, here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
%macro com(c);
%do i=1 %to 12;
proc corr data=on_cl_onl_gr_&amp;amp;i.;
var 
%do j=1 %to %sysfunc(countw(&amp;amp;c));
   %scan(&amp;amp;c,&amp;amp;j,%str( ))_scale_score
%end;
;   
ods output PearsonCorr=corr_gr_&amp;amp;i.;
run;
data corr_gr_&amp;amp;i.;
set corr_gr_&amp;amp;i.;
grade=&amp;amp;i.;
run;
%end;
%mend;
%com(listening reading speaking writing)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would also benefit from a better data structure. It seems that you have data sets named with one of (listening reading speaking writing) in the data set name, and I would recommend you avoid this. If you combine all four of your variables into one data set, then all 12 (indexed by &amp;amp;i) into a single large data set, you would not need a macro at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, it would seem that you haven't followed the first rule of macro writing, that is to create code for one case (like when &amp;amp;i=1) that works WITHOUT macros and without macro variables. Once you have that, you have working template from which you can create a macro. If you can't start with working code without macros and without macro variables, then your macro will never work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Sep 2020 12:00:42 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-20T12:00:42Z</dc:date>
    <item>
      <title>correlation among variables with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correlation-among-variables-with-macro/m-p/685230#M24285</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am trying to calculate the correlation between 4 variables (listening scores, writing scores, speaking scores, reading scores) with macro. It only calculates the correlation between the same variable (for example, the correlation between listening score and listening score ) with below macro. Could you help to find out why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro com(c);&lt;/P&gt;
&lt;P&gt;%do i=1 %to 12;&lt;/P&gt;
&lt;P&gt;proc corr data=on_cl_&amp;amp;c._onl_gr_&amp;amp;i.;&lt;BR /&gt;var &amp;amp;c._scale_score ;&lt;BR /&gt;ods output PearsonCorr=corr_&amp;amp;c._gr_&amp;amp;i.;&lt;BR /&gt;run;&lt;BR /&gt;data corr_&amp;amp;c._gr_&amp;amp;i.;&lt;BR /&gt;set corr_&amp;amp;c._gr_&amp;amp;i.;&lt;BR /&gt;grade=&amp;amp;i.;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%com (listening);&lt;BR /&gt;%com (reading);&lt;BR /&gt;%com (speaking);&lt;BR /&gt;%com (writing);&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 21:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correlation-among-variables-with-macro/m-p/685230#M24285</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2020-09-19T21:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: correlation among variables with macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correlation-among-variables-with-macro/m-p/685231#M24286</link>
      <description>&lt;P&gt;You have only one variable listed in the VAR statement of PROC CORR each time the macro runs. SAS can't read your mind and figure out you really want four variables in the PROC CORR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do a lot of debugging yourself, and identify this problem, if you place the command &lt;FONT face="courier new,courier"&gt;options mprint;&lt;/FONT&gt; at the beginning of your program, run it again, and look at the LOG and see what code has been generated by your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need all four of your variables in the VAR statement to get a correlation matrix. To get this, you will need to merge four data sets together. Then, here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
%macro com(c);
%do i=1 %to 12;
proc corr data=on_cl_onl_gr_&amp;amp;i.;
var 
%do j=1 %to %sysfunc(countw(&amp;amp;c));
   %scan(&amp;amp;c,&amp;amp;j,%str( ))_scale_score
%end;
;   
ods output PearsonCorr=corr_gr_&amp;amp;i.;
run;
data corr_gr_&amp;amp;i.;
set corr_gr_&amp;amp;i.;
grade=&amp;amp;i.;
run;
%end;
%mend;
%com(listening reading speaking writing)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would also benefit from a better data structure. It seems that you have data sets named with one of (listening reading speaking writing) in the data set name, and I would recommend you avoid this. If you combine all four of your variables into one data set, then all 12 (indexed by &amp;amp;i) into a single large data set, you would not need a macro at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, it would seem that you haven't followed the first rule of macro writing, that is to create code for one case (like when &amp;amp;i=1) that works WITHOUT macros and without macro variables. Once you have that, you have working template from which you can create a macro. If you can't start with working code without macros and without macro variables, then your macro will never work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 12:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correlation-among-variables-with-macro/m-p/685231#M24286</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-20T12:00:42Z</dc:date>
    </item>
  </channel>
</rss>

