<?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: Limit the number of merges in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82247#M23670</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommend the match macros from the Mayo Clinic:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros" title="http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros"&gt;http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Jul 2013 14:44:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-07-17T14:44:58Z</dc:date>
    <item>
      <title>Limit the number of merges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82246#M23669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a two datasets - cases and controls. Assume that the dataset 'cases' is a small one with a few hundred patient IDs, while 'controls' is huge dataset with millions of patient IDs. I want to merge cases with controls on say, age variable, such that when a case is merged with 10 controls I want the merging process to stop for that case and move to the next. Is it possible with proc sql or merge (data step)? What would be the modifications in the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table matches as &lt;/P&gt;&lt;P&gt;select a.caseID, a.age, b.controlID, b.age&lt;/P&gt;&lt;P&gt;from cases as a, controls as b&lt;/P&gt;&lt;P&gt;where a.age = b.age;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data matches;&lt;/P&gt;&lt;P&gt;merge cases (in=a) controls (in=b);&lt;/P&gt;&lt;P&gt;by age;&lt;/P&gt;&lt;P&gt;if a and b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 13:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82246#M23669</guid>
      <dc:creator>Sas_Geek</dc:creator>
      <dc:date>2013-07-17T13:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Limit the number of merges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82247#M23670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I recommend the match macros from the Mayo Clinic:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros" title="http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros"&gt;http://www.mayo.edu/research/departments-divisions/department-health-sciences-research/division-biomedical-statistics-informatics/software/locally-written-sas-macros&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 14:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82247#M23670</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-07-17T14:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Limit the number of merges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82248#M23671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok sorry if you received e-mail spam, I fixed something in the post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input age 2. something $4.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;23 aded&lt;/P&gt;&lt;P&gt;23 aaaa&lt;/P&gt;&lt;P&gt;23 add&lt;/P&gt;&lt;P&gt;23 agb&lt;/P&gt;&lt;P&gt;23 aef&lt;/P&gt;&lt;P&gt;24 aa&lt;/P&gt;&lt;P&gt;24 tt&lt;/P&gt;&lt;P&gt;24 ll&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input age 2. somethingelse $2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;23 A&lt;/P&gt;&lt;P&gt;24 B&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge have have2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by age;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.age=1 then byobscounter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if byobscounter LE 2 then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byobscounter=byobscounter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain byobscounter;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop byobscounter;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You won't see a huge gain in efficiency since all the records in the huge table will still be read in the data vector but at least they won't be output and thus won't need to be written on the disk at the end of the merge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vincent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 15:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82248#M23671</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-07-17T15:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Limit the number of merges</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82249#M23672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Almost like Vincent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data controls ;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input age 2. something $4.;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;
23 aded
23 aaaa
23 add
23 agb
23 aef
23 add
23 agb
23 aef
23 add
23 agb
23 aef
23 add
23 agb
23 aef
24 aa
24 tt
24 ll
25 aa
25 rr
25 hh
;
run;

 

data cases ;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input age 2. somethingelse $2.;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;
23 A
24 B
run;

data matches;
merge cases (in=a) controls (in=b);
by age;
if age ne lag(age) then n=0;
n+1;
if a and b and n le 10 then output;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 01:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Limit-the-number-of-merges/m-p/82249#M23672</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-18T01:08:00Z</dc:date>
    </item>
  </channel>
</rss>

