<?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 Sas code for 1:3 matching using Age, Sex and Year Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676911#M204125</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I need help with SAS code for generating a matched cohort using cases (n=23) and controls (n=2199). For every case, I need at least 3 controls. I would like to match these 23 cases to controls using Age, Sex and Year of admission. I have cases and controls as two separate data sets (Dataset A and Dataset B) but the variables names are exactly the same in both (Age, Sex, Year) and the ID variable (Encounter_ID).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using&amp;nbsp; syntax (accepted solution) posted on this community link below, but I was not getting any output for the merge data set step.&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate if anyone can help me with this matching SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;Sat&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 15 Aug 2020 01:37:31 GMT</pubDate>
    <dc:creator>sms1891</dc:creator>
    <dc:date>2020-08-15T01:37:31Z</dc:date>
    <item>
      <title>Sas code for 1:3 matching using Age, Sex and Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676911#M204125</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I need help with SAS code for generating a matched cohort using cases (n=23) and controls (n=2199). For every case, I need at least 3 controls. I would like to match these 23 cases to controls using Age, Sex and Year of admission. I have cases and controls as two separate data sets (Dataset A and Dataset B) but the variables names are exactly the same in both (Age, Sex, Year) and the ID variable (Encounter_ID).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using&amp;nbsp; syntax (accepted solution) posted on this community link below, but I was not getting any output for the merge data set step.&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate if anyone can help me with this matching SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;Sat&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Aug 2020 01:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676911#M204125</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2020-08-15T01:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sas code for 1:3 matching using Age, Sex and Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676916#M204129</link>
      <description>&lt;P&gt;Any data examples would be good. Things to check&lt;/P&gt;
&lt;P&gt;1. Are all the overlapping variables in both the datasets in the same format and datatype. I.e. if they are numeric in one dataset then they are numeric in the other.&lt;/P&gt;
&lt;P&gt;2. If there are overlapping character variables in both the datasets are they of the same length and same case (upper and lower), no padding blanks etc. Off hand Do you know if there is an over lap on these variables.&lt;/P&gt;
&lt;P&gt;3. Are the datasets sorted by the overlapping variables? If there arise a situation where there is many to many join then use proc sql instead of datastep merge. If it is one to many merge you can safely proceed with the data step merge.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coming to the actual problem The following code might work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= test(rename=(id=id_test)); by age sex year; run;

proc&amp;nbsp; sort data=control(rename=(id=id_control)); By age sex year; run;

data want;
merge test control;
by age sex year;&lt;BR /&gt;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;while i was writing above code i felt it would be a many to many merge so might not work right.&amp;nbsp; Alternative code is below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.id as id_test, b.id as id_control , b.age, b.sex,b.year
from test a
,
control b
where a.age = b.age and a.sex=b.sex and a.year=b.year
order by id_test, id_control;

create table freq as
select count(id_test) as count, id_test from want
group by id_test having count &amp;gt;= 3;

create table final as
select a.*
from want a,
freq b
where a.id_test=b.id_test;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Aug 2020 02:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676916#M204129</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-08-15T02:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sas code for 1:3 matching using Age, Sex and Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676918#M204130</link>
      <description>You may want to consider using PROC PSMATCH which is entirely designed for case-control matching - propensity score. The documentation has an example on greedy nearest neighbour matching which would match a 'merge' algorithm. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_psmatch_examples04.htm&amp;amp;docsetVersion=14.2&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_psmatch_examples04.htm&amp;amp;docsetVersion=14.2&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Sat, 15 Aug 2020 02:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/676918#M204130</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-15T02:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sas code for 1:3 matching using Age, Sex and Year Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/677539#M204377</link>
      <description>Thank you! This worked!!!</description>
      <pubDate>Tue, 18 Aug 2020 16:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-code-for-1-3-matching-using-Age-Sex-and-Year-Variables/m-p/677539#M204377</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2020-08-18T16:10:26Z</dc:date>
    </item>
  </channel>
</rss>

