<?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 How to do a 1:1 matching using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870088#M343681</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to do a 1:1 matching where I want to use control once (i.e, 1 case: 1 control).&lt;/P&gt;&lt;P&gt;I found a great &lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf" target="_self"&gt;article/document&lt;/A&gt; showing how to match&amp;nbsp;using proc SQL. The problem is that I want to do 1:1 matching, and I can't figure out how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My codes:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;** split into two datasets;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data case control;&lt;BR /&gt;set sample_1;&lt;BR /&gt;rand_num=uniform(0);&lt;BR /&gt;if Reinfection_Status="yes" then output case;&lt;BR /&gt;else if Reinfection_Status="no" then output control;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** Simple match: exact match on age, race, and month of primary infection;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table controls_id&lt;BR /&gt;as select&lt;BR /&gt;one.PatientID as case_PatientID,&lt;BR /&gt;two.PatientID as control_PatientID,&lt;BR /&gt;one.Age as case_Age,&lt;BR /&gt;two.Age as control_Age,&lt;BR /&gt;one.Ethnicity as case_Ethnicity,&lt;BR /&gt;two.Ethnicity as control_Ethnicity,&lt;BR /&gt;one.Month_Pr as case_Month_Pr,&lt;BR /&gt;two.Month_Pr as control_Month_Pr,&lt;BR /&gt;one.rand_num as rand_num&lt;BR /&gt;from case one, control two&lt;BR /&gt;where (one.Age=two.Age and one.Ethnicity=two.Ethnicity and one.Month_Pr=two.Month_Pr);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;* remove duplicate control subjects;&lt;/P&gt;&lt;P&gt;proc sort data=controls_id nodupkey;&lt;BR /&gt;by control_PatientID rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 1066 cases and 7088 controls, so I want 1066 cases and 1066 controls to run the analysis. When I ran the proc SQL, I had 1736 observations and when I tried to remove duplicate control subjects using proc sort nodupkey, I had 0 observations with duplicates. How should I go from here..?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I'm making sense. Please let me know if you need anything else from me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2023 06:48:22 GMT</pubDate>
    <dc:creator>eeun1ilee</dc:creator>
    <dc:date>2023-04-17T06:48:22Z</dc:date>
    <item>
      <title>How to do a 1:1 matching using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870088#M343681</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to do a 1:1 matching where I want to use control once (i.e, 1 case: 1 control).&lt;/P&gt;&lt;P&gt;I found a great &lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/173-29.pdf" target="_self"&gt;article/document&lt;/A&gt; showing how to match&amp;nbsp;using proc SQL. The problem is that I want to do 1:1 matching, and I can't figure out how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My codes:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;** split into two datasets;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data case control;&lt;BR /&gt;set sample_1;&lt;BR /&gt;rand_num=uniform(0);&lt;BR /&gt;if Reinfection_Status="yes" then output case;&lt;BR /&gt;else if Reinfection_Status="no" then output control;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** Simple match: exact match on age, race, and month of primary infection;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table controls_id&lt;BR /&gt;as select&lt;BR /&gt;one.PatientID as case_PatientID,&lt;BR /&gt;two.PatientID as control_PatientID,&lt;BR /&gt;one.Age as case_Age,&lt;BR /&gt;two.Age as control_Age,&lt;BR /&gt;one.Ethnicity as case_Ethnicity,&lt;BR /&gt;two.Ethnicity as control_Ethnicity,&lt;BR /&gt;one.Month_Pr as case_Month_Pr,&lt;BR /&gt;two.Month_Pr as control_Month_Pr,&lt;BR /&gt;one.rand_num as rand_num&lt;BR /&gt;from case one, control two&lt;BR /&gt;where (one.Age=two.Age and one.Ethnicity=two.Ethnicity and one.Month_Pr=two.Month_Pr);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;* remove duplicate control subjects;&lt;/P&gt;&lt;P&gt;proc sort data=controls_id nodupkey;&lt;BR /&gt;by control_PatientID rand_num;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 1066 cases and 7088 controls, so I want 1066 cases and 1066 controls to run the analysis. When I ran the proc SQL, I had 1736 observations and when I tried to remove duplicate control subjects using proc sort nodupkey, I had 0 observations with duplicates. How should I go from here..?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I'm making sense. Please let me know if you need anything else from me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 06:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870088#M343681</guid>
      <dc:creator>eeun1ilee</dc:creator>
      <dc:date>2023-04-17T06:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a 1:1 matching using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870111#M343690</link>
      <description>&lt;P&gt;I think that you want is to sort by&amp;nbsp;&lt;SPAN&gt;case_PatientID and not&amp;nbsp;control_PatientID.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 09:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870111#M343690</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-04-17T09:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a 1:1 matching using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870112#M343691</link>
      <description>&lt;P&gt;Do a MERGE with no BY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  case (
    keep=patient_id age ethnicity month_pr
    rename=(
      patient_id=case_patient_id
      age=case_age
      ethnicity=case_ethnicity
      month_pr=case_month_pr
    )
  )
  control (
    keep=patient_id age ethnicity month_pr rand_num
    rename=(
      /* see above */
    )
  )
;
set sample_1;
rand_num = rand("uniform");
if Reinfection_Status="yes"
then output case;
else if Reinfection_Status="no" then output control;
run;

proc sort data=control;
by rand_num;
run;

data controls:id;
merge
  case (in=c)
  control
;
if not c then stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 09:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870112#M343691</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-17T09:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a 1:1 matching using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870168#M343708</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/412814"&gt;@eeun1ilee&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you better use PROC SQL SET clauses, it is way easier than SQL joins.&amp;nbsp;&lt;BR /&gt;It does 1:1 match of obs, eliminates duplicate records, and keeps whatever obs needed, like 'cases' in your example .&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Case_Control_Match as
		select* /*you need to specify variables list, in case not interested in all variables to be matched in the dataset*/
			from cases
				except corr
			select* /*you need to specify variables list, in case not interested in all variables to be matched in the dataset*/
		from controls
	order by 1,2,3; /*you need to specify sorting order*/
quit; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Apr 2023 13:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-a-1-1-matching-using-SAS/m-p/870168#M343708</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-17T13:57:18Z</dc:date>
    </item>
  </channel>
</rss>

