<?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 Matching cases to controls without replacement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/873849#M345245</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to match cases to controls randomly in a ratio of 1:5 by sex and age. I have a data set (HAVE - created by PROC SQL step) containing the cases and potential controls, with the variables below; (rand_num - assigned random numbers)&lt;/P&gt;&lt;P&gt;case_id, control_id, case_age, control_age, case_sex, control_sex, rand_num&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I initially used the code below to select 5 controls for each case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=HAVE ;&lt;BR /&gt;by case_id rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WANT not_enough;&lt;BR /&gt;set HAVE;&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 5 then do;&lt;BR /&gt;output WANT;&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 5 then output not_enough;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I modify this in order to select 5 controls for each case without replacement (using controls only once)?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 12:30:20 GMT</pubDate>
    <dc:creator>momolito</dc:creator>
    <dc:date>2023-05-04T12:30:20Z</dc:date>
    <item>
      <title>Matching cases to controls without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/873849#M345245</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to match cases to controls randomly in a ratio of 1:5 by sex and age. I have a data set (HAVE - created by PROC SQL step) containing the cases and potential controls, with the variables below; (rand_num - assigned random numbers)&lt;/P&gt;&lt;P&gt;case_id, control_id, case_age, control_age, case_sex, control_sex, rand_num&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I initially used the code below to select 5 controls for each case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=HAVE ;&lt;BR /&gt;by case_id rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WANT not_enough;&lt;BR /&gt;set HAVE;&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 5 then do;&lt;BR /&gt;output WANT;&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 5 then output not_enough;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I modify this in order to select 5 controls for each case without replacement (using controls only once)?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 12:30:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/873849#M345245</guid>
      <dc:creator>momolito</dc:creator>
      <dc:date>2023-05-04T12:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Matching cases to controls without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/873854#M345246</link>
      <description>Try to look at proc SURVEYSELECT</description>
      <pubDate>Thu, 04 May 2023 12:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/873854#M345246</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2023-05-04T12:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Matching cases to controls without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874236#M345383</link>
      <description>&lt;P&gt;I have tried to use Proc surveyselect as you suggested with the code below. note - at this point I have 2 dataset, one for CONTROLS (n=&amp;gt;10000) and another for CASES (n=986). each contains the id, age and sex. I am trying to match in a ratio of 1:5 without repeating controls.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc surveyselect data=CONTROLS method=srs out=matched_controls seed=12345 noprint samprate=5;&lt;BR /&gt;strata AGE SEX;&lt;BR /&gt;id ID;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table matched_pair as&lt;BR /&gt;select a.ID as case_id, b.ID as control_id&lt;BR /&gt;from cases a, matched_controls b&lt;BR /&gt;where a.age between b.age-5 and b.age+5&lt;BR /&gt;and a.sex = b.sex&lt;BR /&gt;and row_number()OVER(partition by a.Release_No)as &amp;lt;= 5;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my outcome still has duplicate controls and is not matching at the 1:5 ratio. How can i modify this to achieve what i want? I am quite new to SAS. Thanks in advance&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 04:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874236#M345383</guid>
      <dc:creator>momolito</dc:creator>
      <dc:date>2023-05-06T04:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Matching cases to controls without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874239#M345385</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;&amp;nbsp;I have a data set (HAVE - created by PROC SQL step) containing the cases and potential controls"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please share your have data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 05:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874239#M345385</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-05-06T05:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Matching cases to controls without replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874242#M345387</link>
      <description>&lt;P&gt;Hello Patrick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached my 'Have' dataset (from the SQL step), as well as the cases and controls datasets.&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 08:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-cases-to-controls-without-replacement/m-p/874242#M345387</guid>
      <dc:creator>momolito</dc:creator>
      <dc:date>2023-05-06T08:07:46Z</dc:date>
    </item>
  </channel>
</rss>

