<?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 1:1  matching only using controls once in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804183#M316648</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do 1:1 matching while only using controls subjects once. I found the following code in a published paper&amp;nbsp; (&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf&lt;/A&gt;&amp;nbsp; ) and I have adapted it for my project. I am able to identify matching based on my matching criteria BUT, the code allows controls to be used more than once. Can someone show me how to adapt this code for 1:1 matching without duplicating controls?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE table possmatch&lt;BR /&gt;as select&lt;BR /&gt;one.del_id as case_id,&lt;BR /&gt;two.del_id as control_id,&lt;BR /&gt;one.case_preg_num as study_parity,&lt;BR /&gt;two.parity_control as control_parity,&lt;BR /&gt;one.case_age as study_age,&lt;BR /&gt;two.control_age as control_age,&lt;BR /&gt;one.gender as study_gender,&lt;BR /&gt;two.gender_control as control_gender,&lt;BR /&gt;one.insurance as study_insurance,&lt;BR /&gt;two.insurance_control as control_insurance,&lt;BR /&gt;one.case_year as study_year,&lt;BR /&gt;two.control_year as year_control,&lt;BR /&gt;one.rand_num as rand_num&lt;BR /&gt;from cases one, controls two&lt;BR /&gt;where ((one.case_year between two.year_low and two.year_high)and&lt;BR /&gt;one.gender=two.gender_control and one.insurance=two.insurance_control&lt;BR /&gt;and one.case_age=two.control_age and one.case_preg_num=two.parity_control);&lt;BR /&gt;run;&lt;BR /&gt;* count the number of control subjects for each case subject;&lt;BR /&gt;proc sort data=possmatch;&lt;BR /&gt;by case_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch2(keep=case_id num_controls);&lt;BR /&gt;set possmatch;&lt;BR /&gt;by case_id;&lt;BR /&gt;retain num_controls;&lt;BR /&gt;if first.case_id then num_controls=1;&lt;BR /&gt;else num_controls=num_controls+1;&lt;BR /&gt;if last.case_id then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* now merge the counts back into the dataset;&lt;BR /&gt;data possmatch3;&lt;BR /&gt;merge possmatch possmatch2;&lt;BR /&gt;by case_id;&lt;BR /&gt;run;&lt;BR /&gt;* now order the rows to select the first matching control;&lt;BR /&gt;proc sort data=possmatch3;&lt;BR /&gt;by control_id num_controls rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=possmatch3 nodup;&lt;BR /&gt;by control_id case_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch4;&lt;BR /&gt;set possmatch3;&lt;BR /&gt;by control_id case_id;&lt;BR /&gt;if first.control_id then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Now, as before, randomly select the fixed number of control subjects for each case.*/&lt;BR /&gt;proc sort data=possmatch ;&lt;BR /&gt;by case_id rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch2 not_enough;&lt;BR /&gt;set possmatch;&lt;BR /&gt;by case_id ;&lt;BR /&gt;retain num;&lt;BR /&gt;if first.case_id then num=1;&lt;BR /&gt;if num le 2 then do;&lt;BR /&gt;output possmatch2;&lt;BR /&gt;num=num+1;&lt;BR /&gt;end;&lt;BR /&gt;if last.case_id then do;&lt;BR /&gt;if num le 2 then output not_enough;&lt;BR /&gt;end;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 21:19:44 GMT</pubDate>
    <dc:creator>GAL1986</dc:creator>
    <dc:date>2022-03-25T21:19:44Z</dc:date>
    <item>
      <title>1:1  matching only using controls once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804183#M316648</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do 1:1 matching while only using controls subjects once. I found the following code in a published paper&amp;nbsp; (&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf&lt;/A&gt;&amp;nbsp; ) and I have adapted it for my project. I am able to identify matching based on my matching criteria BUT, the code allows controls to be used more than once. Can someone show me how to adapt this code for 1:1 matching without duplicating controls?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE table possmatch&lt;BR /&gt;as select&lt;BR /&gt;one.del_id as case_id,&lt;BR /&gt;two.del_id as control_id,&lt;BR /&gt;one.case_preg_num as study_parity,&lt;BR /&gt;two.parity_control as control_parity,&lt;BR /&gt;one.case_age as study_age,&lt;BR /&gt;two.control_age as control_age,&lt;BR /&gt;one.gender as study_gender,&lt;BR /&gt;two.gender_control as control_gender,&lt;BR /&gt;one.insurance as study_insurance,&lt;BR /&gt;two.insurance_control as control_insurance,&lt;BR /&gt;one.case_year as study_year,&lt;BR /&gt;two.control_year as year_control,&lt;BR /&gt;one.rand_num as rand_num&lt;BR /&gt;from cases one, controls two&lt;BR /&gt;where ((one.case_year between two.year_low and two.year_high)and&lt;BR /&gt;one.gender=two.gender_control and one.insurance=two.insurance_control&lt;BR /&gt;and one.case_age=two.control_age and one.case_preg_num=two.parity_control);&lt;BR /&gt;run;&lt;BR /&gt;* count the number of control subjects for each case subject;&lt;BR /&gt;proc sort data=possmatch;&lt;BR /&gt;by case_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch2(keep=case_id num_controls);&lt;BR /&gt;set possmatch;&lt;BR /&gt;by case_id;&lt;BR /&gt;retain num_controls;&lt;BR /&gt;if first.case_id then num_controls=1;&lt;BR /&gt;else num_controls=num_controls+1;&lt;BR /&gt;if last.case_id then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* now merge the counts back into the dataset;&lt;BR /&gt;data possmatch3;&lt;BR /&gt;merge possmatch possmatch2;&lt;BR /&gt;by case_id;&lt;BR /&gt;run;&lt;BR /&gt;* now order the rows to select the first matching control;&lt;BR /&gt;proc sort data=possmatch3;&lt;BR /&gt;by control_id num_controls rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=possmatch3 nodup;&lt;BR /&gt;by control_id case_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch4;&lt;BR /&gt;set possmatch3;&lt;BR /&gt;by control_id case_id;&lt;BR /&gt;if first.control_id then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Now, as before, randomly select the fixed number of control subjects for each case.*/&lt;BR /&gt;proc sort data=possmatch ;&lt;BR /&gt;by case_id rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data possmatch2 not_enough;&lt;BR /&gt;set possmatch;&lt;BR /&gt;by case_id ;&lt;BR /&gt;retain num;&lt;BR /&gt;if first.case_id then num=1;&lt;BR /&gt;if num le 2 then do;&lt;BR /&gt;output possmatch2;&lt;BR /&gt;num=num+1;&lt;BR /&gt;end;&lt;BR /&gt;if last.case_id then do;&lt;BR /&gt;if num le 2 then output not_enough;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 21:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804183#M316648</guid>
      <dc:creator>GAL1986</dc:creator>
      <dc:date>2022-03-25T21:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: 1:1  matching only using controls once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804253#M316698</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I haven't read your program (nor the paper it is based on), but the easiest technique is :&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;to delete the already matched controls from the data set "&lt;/SPAN&gt;&lt;EM style="box-sizing: inherit; color: #212121; font-family: Cambria, 'Cambria Math', stixgeneral, 'Times New Roman', Times, serif; font-size: 20px; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"&gt;controls&lt;/EM&gt;"&lt;SPAN&gt; in order to ensure that controls are used only once.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That technique is used in the program that is presented in this paper :&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Matching Cases and Controls Using SAS® Software&lt;BR /&gt;Laura Quitzau Mortensen, Kristoffer Andresen, Jakob Burcharth, Hans-Christian Pommergaard, and Jacob Rosenberg&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7931898/" target="_blank"&gt;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7931898/&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Koen&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 12:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804253#M316698</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-03-26T12:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: 1:1  matching only using controls once</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804287#M316715</link>
      <description>Thank you, I will take a look at that reference.&lt;BR /&gt;</description>
      <pubDate>Sat, 26 Mar 2022 18:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-1-matching-only-using-controls-once/m-p/804287#M316715</guid>
      <dc:creator>GAL1986</dc:creator>
      <dc:date>2022-03-26T18:27:54Z</dc:date>
    </item>
  </channel>
</rss>

