<?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: proc sql within a mcaro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246441#M46106</link>
    <description>Thank you. I am not familiar with this but I will look into it.</description>
    <pubDate>Wed, 27 Jan 2016 20:05:59 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-01-27T20:05:59Z</dc:date>
    <item>
      <title>proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246414#M46089</link>
      <description>&lt;P&gt;I have 7 similar data sets, and I want to select cases that exist in two data sets, so I have 21 combinations of 2 of the 7 sets.&lt;/P&gt;
&lt;P&gt;so I want to use a macro to speed this up. Below is my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro both(A,B);
proc sql;
create table &amp;amp;A&amp;amp;B as 
select A.ID, A.Gender, A.age
from &amp;amp;A.demographics as A, &amp;amp;B.demographics as B
where A.ID = B.ID;
quit;&lt;BR /&gt;&lt;BR /&gt;* then count;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select&amp;nbsp; count(*)&lt;BR /&gt;into&amp;nbsp;&amp;nbsp;&amp;nbsp; :OBSCOUNT&lt;BR /&gt;from&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;A&amp;amp;B&lt;BR /&gt;quit;&lt;BR /&gt;%put Count=&amp;amp;OBSCOUNT.;&lt;BR /&gt;
%mend both;

%both(data1,data2)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It works. But I still have to type the 21 combinations, like %both(data1,data2), %both(data1,data3), ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I improve it with a do loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also, in the last step,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Count=&amp;amp;OBSCOUNT.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can I print out the two data sets names, &amp;amp;A and &amp;amp;B? how?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 18:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246414#M46089</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-01-27T18:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246415#M46090</link>
      <description>&lt;P&gt;Look at the CALL EXECUTE documentation.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 17:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246415#M46090</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-27T17:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246424#M46096</link>
      <description>&lt;P&gt;Assuming you want to call a macro to do the work for you and cut down on the possibility of human error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%overlap (list=A B C D E F G)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here would be a way to program it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro overlap (list=);&lt;/P&gt;
&lt;P&gt;%local i j n;&lt;/P&gt;
&lt;P&gt;%let n = %sysfunc(countw, &amp;amp;list);&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n-1;&lt;/P&gt;
&lt;P&gt;%do j=&amp;amp;i+1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %both (%scan(&amp;amp;list, &amp;amp;i), %scan(&amp;amp;list, &amp;amp;j))&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend overlap;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can always modify the %PUT statement inside %BOTH:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put COUNT=&amp;amp;obscount&amp;nbsp; A=&amp;amp;a B=&amp;amp;b;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246424#M46096</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-27T19:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246432#M46100</link>
      <description>Thank you. I got an error: ERROR: Expected open parenthesis after macro function name not found.&lt;BR /&gt;&lt;BR /&gt;I am searching about it.</description>
      <pubDate>Wed, 27 Jan 2016 19:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246432#M46100</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-01-27T19:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246436#M46103</link>
      <description>&lt;P&gt;My fault.&amp;nbsp; (The code is untested.)&amp;nbsp; This is wrong:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = %sysfunc(countw, &amp;amp;list);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n = %sysfunc(countw(&amp;amp;list));&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 20:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246436#M46103</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-27T20:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246440#M46105</link>
      <description>Yes, it works well. Thank you. &lt;BR /&gt;I have learned a lot again from you!</description>
      <pubDate>Wed, 27 Jan 2016 20:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246440#M46105</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-01-27T20:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql within a mcaro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246441#M46106</link>
      <description>Thank you. I am not familiar with this but I will look into it.</description>
      <pubDate>Wed, 27 Jan 2016 20:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-within-a-mcaro/m-p/246441#M46106</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-01-27T20:05:59Z</dc:date>
    </item>
  </channel>
</rss>

